diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-07-07 23:07:06 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-07-08 18:16:09 +0300 |
| commit | fc74e359819002fad402f68728f6e5ba2d4cb704 (patch) | |
| tree | 32c1c6b774ff39648ef7508739ef83975358996e /src/test | |
| parent | 94ef9f57f5fa985beb7588e5cb4c73f1b5f2dcba (diff) | |
| download | rust-fc74e359819002fad402f68728f6e5ba2d4cb704.tar.gz rust-fc74e359819002fad402f68728f6e5ba2d4cb704.zip | |
Remove fallback to parent modules from lexical resolution
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui-fulldeps/proc-macro/auxiliary/generate-mod.rs | 26 | ||||
| -rw-r--r-- | src/test/ui-fulldeps/proc-macro/generate-mod.rs | 17 | ||||
| -rw-r--r-- | src/test/ui-fulldeps/proc-macro/generate-mod.stderr | 43 | ||||
| -rw-r--r-- | src/test/ui/hygiene/arguments.rs (renamed from src/test/run-pass/hygiene/arguments.rs) | 2 | ||||
| -rw-r--r-- | src/test/ui/hygiene/arguments.stderr | 9 | ||||
| -rw-r--r-- | src/test/ui/hygiene/generate-mod.rs | 43 | ||||
| -rw-r--r-- | src/test/ui/hygiene/generate-mod.stderr | 53 | ||||
| -rw-r--r-- | src/test/ui/hygiene/globs.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/hygiene/globs.stderr | 16 |
9 files changed, 203 insertions, 22 deletions
diff --git a/src/test/ui-fulldeps/proc-macro/auxiliary/generate-mod.rs b/src/test/ui-fulldeps/proc-macro/auxiliary/generate-mod.rs index 1741b0eed89..6a8d545db49 100644 --- a/src/test/ui-fulldeps/proc-macro/auxiliary/generate-mod.rs +++ b/src/test/ui-fulldeps/proc-macro/auxiliary/generate-mod.rs @@ -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() +} diff --git a/src/test/ui-fulldeps/proc-macro/generate-mod.rs b/src/test/ui-fulldeps/proc-macro/generate-mod.rs index 509cd33d93d..ff64421047f 100644 --- a/src/test/ui-fulldeps/proc-macro/generate-mod.rs +++ b/src/test/ui-fulldeps/proc-macro/generate-mod.rs @@ -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() {} diff --git a/src/test/ui-fulldeps/proc-macro/generate-mod.stderr b/src/test/ui-fulldeps/proc-macro/generate-mod.stderr index 80213b04dce..c024aeffbb0 100644 --- a/src/test/ui-fulldeps/proc-macro/generate-mod.stderr +++ b/src/test/ui-fulldeps/proc-macro/generate-mod.stderr @@ -1,9 +1,46 @@ +error[E0412]: cannot find type `FromOutside` 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 `Outer` in this scope - --> $DIR/generate-mod.rs:19:1 + --> $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 `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`. diff --git a/src/test/run-pass/hygiene/arguments.rs b/src/test/ui/hygiene/arguments.rs index 5d9e1863847..958133e7ec5 100644 --- a/src/test/run-pass/hygiene/arguments.rs +++ b/src/test/ui/hygiene/arguments.rs @@ -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 } diff --git a/src/test/ui/hygiene/arguments.stderr b/src/test/ui/hygiene/arguments.stderr new file mode 100644 index 00000000000..1b0c23eff29 --- /dev/null +++ b/src/test/ui/hygiene/arguments.stderr @@ -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`. diff --git a/src/test/ui/hygiene/generate-mod.rs b/src/test/ui/hygiene/generate-mod.rs index 90409857dea..2b2108558a0 100644 --- a/src/test/ui/hygiene/generate-mod.rs +++ b/src/test/ui/hygiene/generate-mod.rs @@ -12,13 +12,46 @@ #![feature(decl_macro, rustc_attrs)] +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 + } +} + #[rustc_transparent_macro] -macro genmod() { - mod m { - type A = S; //~ ERROR cannot find type `S` in this scope +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 } } -struct S; +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 + } +}} -genmod!(); +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!(); +} diff --git a/src/test/ui/hygiene/generate-mod.stderr b/src/test/ui/hygiene/generate-mod.stderr index e79f8528c2c..0c5905c5acb 100644 --- a/src/test/ui/hygiene/generate-mod.stderr +++ b/src/test/ui/hygiene/generate-mod.stderr @@ -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_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!(); - | ---------- in this macro invocation +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`. diff --git a/src/test/ui/hygiene/globs.rs b/src/test/ui/hygiene/globs.rs index 7ba217061c6..9785ce6c004 100644 --- a/src/test/ui/hygiene/globs.rs +++ b/src/test/ui/hygiene/globs.rs @@ -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 + } } } } diff --git a/src/test/ui/hygiene/globs.stderr b/src/test/ui/hygiene/globs.stderr index d77242e135d..7df2e31f9a7 100644 --- a/src/test/ui/hygiene/globs.stderr +++ b/src/test/ui/hygiene/globs.stderr @@ -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: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:64:17 + --> $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`. |
