Remove fallback to parent modules from lexical resolution

This commit is contained in:
Vadim Petrochenkov 2018-07-07 23:07:06 +03:00
parent 94ef9f57f5
commit fc74e35981
16 changed files with 320 additions and 105 deletions

View file

@ -20,9 +20,35 @@ use proc_macro::*;
#[proc_macro]
pub fn check(_: TokenStream) -> TokenStream {
"
type Alias = FromOutside; // OK
struct Outer;
mod inner {
type Alias = FromOutside; // `FromOutside` shouldn't be available from here
type Inner = Outer; // `Outer` shouldn't be available from here
}
".parse().unwrap()
}
#[proc_macro_attribute]
pub fn check_attr(_: TokenStream, _: TokenStream) -> TokenStream {
"
type AliasAttr = FromOutside; // OK
struct OuterAttr;
mod inner_attr {
type Alias = FromOutside; // `FromOutside` shouldn't be available from here
type Inner = OuterAttr; // `OuterAttr` shouldn't be available from here
}
".parse().unwrap()
}
#[proc_macro_derive(CheckDerive)]
pub fn check_derive(_: TokenStream) -> TokenStream {
"
type AliasDerive = FromOutside; // OK
struct OuterDerive;
mod inner_derive {
type Alias = FromOutside; // `FromOutside` shouldn't be available from here
type Inner = OuterDerive; // `OuterDerive` shouldn't be available from here
}
".parse().unwrap()
}

View file

@ -12,10 +12,23 @@
// aux-build:generate-mod.rs
#![feature(proc_macro, proc_macro_gen)]
#![feature(proc_macro, proc_macro_gen, proc_macro_path_invoc)]
extern crate generate_mod;
generate_mod::check!(); //~ ERROR cannot find type `Outer` in this scope
struct FromOutside;
generate_mod::check!(); //~ ERROR cannot find type `FromOutside` in this scope
//~| ERROR cannot find type `Outer` in this scope
#[generate_mod::check_attr] //~ ERROR cannot find type `FromOutside` in this scope
//~| ERROR cannot find type `OuterAttr` in this scope
struct S;
#[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope
//~| WARN cannot find type `OuterDerive` in this scope
//~| WARN this was previously accepted
//~| WARN this was previously accepted
struct Z;
fn main() {}

View file

@ -1,9 +1,46 @@
error[E0412]: cannot find type `Outer` in this scope
--> $DIR/generate-mod.rs:19:1
error[E0412]: cannot find type `FromOutside` in this scope
--> $DIR/generate-mod.rs:21:1
|
LL | generate_mod::check!(); //~ ERROR cannot find type `Outer` in this scope
LL | generate_mod::check!(); //~ ERROR cannot find type `FromOutside` in this scope
| ^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
error: aborting due to previous error
error[E0412]: cannot find type `Outer` in this scope
--> $DIR/generate-mod.rs:21:1
|
LL | generate_mod::check!(); //~ ERROR cannot find type `FromOutside` in this scope
| ^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `FromOutside` in this scope
--> $DIR/generate-mod.rs:24:1
|
LL | #[generate_mod::check_attr] //~ ERROR cannot find type `FromOutside` in this scope
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `OuterAttr` in this scope
--> $DIR/generate-mod.rs:24:1
|
LL | #[generate_mod::check_attr] //~ ERROR cannot find type `FromOutside` in this scope
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
warning: cannot find type `FromOutside` in this scope
--> $DIR/generate-mod.rs:28:10
|
LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope
| ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
|
= note: #[warn(proc_macro_derive_resolution_fallback)] on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
warning: cannot find type `OuterDerive` in this scope
--> $DIR/generate-mod.rs:28:10
|
LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope
| ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0412`.

View file

@ -23,5 +23,5 @@ macro m($t:ty, $e:expr) {
fn main() {
struct S;
m!(S, S);
m!(S, S); //~ ERROR cannot find type `S` in this scope
}

View file

@ -0,0 +1,9 @@
error[E0412]: cannot find type `S` in this scope
--> $DIR/arguments.rs:26:8
|
LL | m!(S, S); //~ ERROR cannot find type `S` in this scope
| ^ not found in this scope
error: aborting due to previous error
For more information about this error, try `rustc --explain E0412`.

View file

@ -12,13 +12,46 @@
#![feature(decl_macro, rustc_attrs)]
#[rustc_transparent_macro]
macro genmod() {
mod m {
type A = S; //~ ERROR cannot find type `S` in this scope
macro genmod($FromOutside: ident, $Outer: ident) {
type A = $FromOutside;
struct $Outer;
mod inner {
type A = $FromOutside; // `FromOutside` shouldn't be available from here
type Inner = $Outer; // `Outer` shouldn't be available from here
}
}
struct S;
#[rustc_transparent_macro]
macro genmod_transparent() {
type A = FromOutside;
struct Outer;
mod inner {
type A = FromOutside; //~ ERROR cannot find type `FromOutside` in this scope
type Inner = Outer; //~ ERROR cannot find type `Outer` in this scope
}
}
genmod!();
macro_rules! genmod_legacy { () => {
type A = FromOutside;
struct Outer;
mod inner {
type A = FromOutside; //~ ERROR cannot find type `FromOutside` in this scope
type Inner = Outer; //~ ERROR cannot find type `Outer` in this scope
}
}}
fn check() {
struct FromOutside;
genmod!(FromOutside, Outer); //~ ERROR cannot find type `FromOutside` in this scope
//~| ERROR cannot find type `Outer` in this scope
}
fn check_transparent() {
struct FromOutside;
genmod_transparent!();
}
fn check_legacy() {
struct FromOutside;
genmod_legacy!();
}

View file

@ -1,17 +1,56 @@
error[E0412]: cannot find type `S` in this scope
--> $DIR/generate-mod.rs:18:18
error[E0412]: cannot find type `FromOutside` in this scope
--> $DIR/generate-mod.rs:45:13
|
LL | type A = S; //~ ERROR cannot find type `S` in this scope
| ^ did you mean `A`?
LL | genmod!(FromOutside, Outer); //~ ERROR cannot find type `FromOutside` in this scope
| ^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `Outer` in this scope
--> $DIR/generate-mod.rs:45:26
|
LL | genmod!(FromOutside, Outer); //~ ERROR cannot find type `FromOutside` in this scope
| ^^^^^ not found in this scope
error[E0412]: cannot find type `FromOutside` in this scope
--> $DIR/generate-mod.rs:29:18
|
LL | type A = FromOutside; //~ ERROR cannot find type `FromOutside` in this scope
| ^^^^^^^^^^^ not found in this scope
...
LL | genmod!();
| ---------- in this macro invocation
LL | genmod_transparent!();
| ---------------------- in this macro invocation
error[E0412]: cannot find type `Outer` in this scope
--> $DIR/generate-mod.rs:30:22
|
LL | type Inner = Outer; //~ ERROR cannot find type `Outer` in this scope
| ^^^^^ not found in this scope
...
LL | genmod_transparent!();
| ---------------------- in this macro invocation
error[E0412]: cannot find type `FromOutside` in this scope
--> $DIR/generate-mod.rs:38:18
|
LL | type A = FromOutside; //~ ERROR cannot find type `FromOutside` in this scope
| ^^^^^^^^^^^ not found in this scope
...
LL | genmod_legacy!();
| ----------------- in this macro invocation
error[E0412]: cannot find type `Outer` in this scope
--> $DIR/generate-mod.rs:39:22
|
LL | type Inner = Outer; //~ ERROR cannot find type `Outer` in this scope
| ^^^^^ not found in this scope
...
LL | genmod_legacy!();
| ----------------- in this macro invocation
error[E0601]: `main` function not found in crate `generate_mod`
|
= note: consider adding a `main` function to `$DIR/generate-mod.rs`
error: aborting due to 2 previous errors
error: aborting due to 7 previous errors
Some errors occurred: E0412, E0601.
For more information about an error, try `rustc --explain E0412`.

View file

@ -57,12 +57,26 @@ macro n($i:ident) {
}
}
}
macro n_with_super($j:ident) {
mod test {
use super::*;
fn g() {
let _: u32 = $i();
let _: () = f();
super::$j();
}
}
}
n!(f);
n!(f); //~ ERROR cannot find function `f` in this scope
n_with_super!(f);
mod test2 {
super::n! {
f //~ ERROR cannot find function `f` in this scope
}
super::n_with_super! {
f
}
}
}
}

View file

@ -30,13 +30,23 @@ LL | use bar::g;
|
LL | use foo::test2::test::g;
|
LL | use foo::test::g;
LL | use foo::test2::test::g;
|
LL | use foo::test::g;
|
and 2 other candidates
error[E0425]: cannot find function `f` in this scope
--> $DIR/globs.rs:64:17
--> $DIR/globs.rs:71:12
|
LL | n!(f);
| ------ in this macro invocation
...
LL | n!(f); //~ ERROR cannot find function `f` in this scope
| ^ not found in this scope
error[E0425]: cannot find function `f` in this scope
--> $DIR/globs.rs:75:17
|
LL | n!(f);
| ------ in this macro invocation
@ -44,6 +54,6 @@ LL | n!(f);
LL | f //~ ERROR cannot find function `f` in this scope
| ^ not found in this scope
error: aborting due to 3 previous errors
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0425`.