resolve: Fully prohibit shadowing of in-scope names by globs in macro paths

This commit is contained in:
Vadim Petrochenkov 2018-07-20 01:11:30 +03:00
parent 2eb83ee527
commit 32453db332
4 changed files with 95 additions and 3 deletions

View file

@ -588,8 +588,7 @@ impl<'a> Resolver<'a> {
return potential_illegal_shadower;
}
}
if binding.expansion != Mark::root() ||
(binding.is_glob_import() && module.unwrap().def().is_some()) {
if binding.is_glob_import() || binding.expansion != Mark::root() {
potential_illegal_shadower = result;
} else {
return result;

View file

@ -233,7 +233,7 @@ impl<'a> Resolver<'a> {
// What on earth is this?
// Apparently one more subtle interaction with `resolve_lexical_macro_path_segment`
// that are going to be removed in the next commit.
if restricted_shadowing && module.def().is_some() {
if restricted_shadowing {
return Err(Determined);
}

View file

@ -0,0 +1,44 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(decl_macro)]
mod m {
pub macro env($e: expr) { $e }
pub macro fenv() { 0 }
}
mod glob_in_normal_module {
use m::*;
fn check() {
let x = env!("PATH"); //~ ERROR `env` is ambiguous
}
}
mod glob_in_block_module {
fn block() {
use m::*;
fn check() {
let x = env!("PATH"); //~ ERROR `env` is ambiguous
}
}
}
mod glob_shadows_item {
pub macro fenv($e: expr) { $e }
fn block() {
use m::*;
fn check() {
let x = fenv!(); //~ ERROR `fenv` is ambiguous
}
}
}
fn main() {}

View file

@ -0,0 +1,49 @@
error[E0659]: `env` is ambiguous
--> $DIR/glob-shadowing.rs:21:17
|
LL | let x = env!("PATH"); //~ ERROR `env` is ambiguous
| ^^^
|
note: `env` could refer to the name imported here
--> $DIR/glob-shadowing.rs:19:9
|
LL | use m::*;
| ^^^^
= note: `env` is also a builtin macro
= note: consider adding an explicit import of `env` to disambiguate
error[E0659]: `env` is ambiguous
--> $DIR/glob-shadowing.rs:29:21
|
LL | let x = env!("PATH"); //~ ERROR `env` is ambiguous
| ^^^
|
note: `env` could refer to the name imported here
--> $DIR/glob-shadowing.rs:27:13
|
LL | use m::*;
| ^^^^
= note: `env` is also a builtin macro
= note: consider adding an explicit import of `env` to disambiguate
error[E0659]: `fenv` is ambiguous
--> $DIR/glob-shadowing.rs:39:21
|
LL | let x = fenv!(); //~ ERROR `fenv` is ambiguous
| ^^^^
|
note: `fenv` could refer to the name imported here
--> $DIR/glob-shadowing.rs:37:13
|
LL | use m::*;
| ^^^^
note: `fenv` could also refer to the name defined here
--> $DIR/glob-shadowing.rs:35:5
|
LL | pub macro fenv($e: expr) { $e }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: consider adding an explicit import of `fenv` to disambiguate
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0659`.