Remove fallback to parent modules from lexical resolution
This commit is contained in:
parent
94ef9f57f5
commit
fc74e35981
16 changed files with 320 additions and 105 deletions
27
src/test/ui/hygiene/arguments.rs
Normal file
27
src/test/ui/hygiene/arguments.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// ignore-pretty pretty-printing is unhygienic
|
||||
|
||||
#![feature(decl_macro)]
|
||||
|
||||
macro m($t:ty, $e:expr) {
|
||||
mod foo {
|
||||
#[allow(unused)]
|
||||
struct S;
|
||||
pub(super) fn f(_: $t) {}
|
||||
}
|
||||
foo::f($e);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
struct S;
|
||||
m!(S, S); //~ ERROR cannot find type `S` in this scope
|
||||
}
|
||||
9
src/test/ui/hygiene/arguments.stderr
Normal file
9
src/test/ui/hygiene/arguments.stderr
Normal 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`.
|
||||
|
|
@ -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!();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue