Navigation Menu

Skip to content

Commit

Permalink
Add checks for expected macro output in restricted shadowing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Sep 8, 2018
1 parent ae2e5aa commit 9beb5c3
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 116 deletions.
2 changes: 2 additions & 0 deletions src/librustc_resolve/lib.rs
Expand Up @@ -1274,6 +1274,8 @@ impl<'a> NameBinding<'a> {
// expansion round `max(invoc_id, binding)` when they both emerged from macros.
// Then this function returns `true` if `self` may emerge from a macro *after* that
// in some later round and screw up our previously found resolution.
// See more detailed explanation in
// https://github.com/rust-lang/rust/pull/53778#issuecomment-419224049
fn may_appear_after(&self, invoc_id: Mark, binding: &NameBinding) -> bool {
// self > max(invoc_id, binding) => !(self <= invoc_id || self <= binding)
// Expansions are partially ordered, so "may appear after" is an inversion of
Expand Down
48 changes: 28 additions & 20 deletions src/test/ui/macros/restricted-shadowing-legacy.rs
@@ -1,4 +1,9 @@
// Legend:
// `N` - number of combination, from 0 to 4*4*4=64
// `Outer < Invoc` means that expansion that produced macro definition `Outer`
// is a strict ancestor of expansion that produced macro definition `Inner`.
// `>`, `=` and `Unordered` mean "strict descendant", "same" and
// "not in ordering relation" for parent expansions.
// `+` - possible configuration
// `-` - configuration impossible due to properties of partial ordering
// `-?` - configuration impossible due to block/scope syntax
Expand Down Expand Up @@ -72,12 +77,15 @@

#![feature(decl_macro, rustc_attrs)]

struct Right;
// struct Wrong; // not defined

macro_rules! include { () => {
macro_rules! gen_outer { () => {
macro_rules! m { () => {} }
macro_rules! m { () => { Wrong } }
}}
macro_rules! gen_inner { () => {
macro_rules! m { () => {} }
macro_rules! m { () => { Right } }
}}
macro_rules! gen_invoc { () => {
m!()
Expand All @@ -96,29 +104,29 @@ macro_rules! include { () => {
}

fn check5() {
macro_rules! m { () => {} }
macro_rules! m { () => { Wrong } }

macro_rules! gen_inner_invoc { () => {
macro_rules! m { () => {} }
macro_rules! m { () => { Right } }
m!(); // OK
}}
gen_inner_invoc!();
}

fn check9() {
macro_rules! m { () => {} }
macro_rules! m { () => { Wrong } }

macro_rules! gen_inner_gen_invoc { () => {
macro_rules! m { () => {} }
macro_rules! m { () => { Right } }
gen_invoc!(); // OK
}}
gen_inner_gen_invoc!();
}

fn check10() {
macro_rules! m { () => {} }
macro_rules! m { () => { Wrong } }

macro_rules! m { () => {} }
macro_rules! m { () => { Right } }

gen_invoc!(); // OK
}
Expand All @@ -141,9 +149,9 @@ macro_rules! include { () => {
}

fn check22() {
macro_rules! m { () => {} }
macro_rules! m { () => { Wrong } }

macro_rules! m { () => {} }
macro_rules! m { () => { Right } }

m!(); // OK
}
Expand All @@ -159,7 +167,7 @@ macro_rules! include { () => {
fn check39() {
gen_outer!();

macro_rules! m { () => {} }
macro_rules! m { () => { Right } }

m!(); // OK
}
Expand All @@ -178,7 +186,7 @@ macro_rules! include { () => {
gen_outer!();

macro_rules! gen_inner_invoc { () => {
macro_rules! m { () => {} }
macro_rules! m { () => { Right } }
m!(); // OK
}}
gen_inner_invoc!();
Expand All @@ -187,7 +195,7 @@ macro_rules! include { () => {
fn check59() {
gen_outer!();

macro_rules! m { () => {} }
macro_rules! m { () => { Right } }

gen_invoc!(); // OK
}
Expand All @@ -196,7 +204,7 @@ macro_rules! include { () => {
gen_outer!();

macro_rules! gen_inner_gen_invoc { () => {
macro_rules! m { () => {} }
macro_rules! m { () => { Right } }
gen_invoc!(); // OK
}}
gen_inner_gen_invoc!();
Expand Down Expand Up @@ -226,8 +234,8 @@ macro_rules! include { () => {

fn check34() {
macro_rules! gen_outer_inner { () => {
macro_rules! m { () => {} }
macro_rules! m { () => {} }
macro_rules! m { () => { Wrong } }
macro_rules! m { () => { Right } }
}}
gen_outer_inner!();

Expand All @@ -237,7 +245,7 @@ macro_rules! include { () => {
fn check35() {
macro_rules! gen_gen_outer_inner { () => {
gen_outer!();
macro_rules! m { () => {} }
macro_rules! m { () => { Right } }
}}
gen_gen_outer_inner!();

Expand All @@ -257,8 +265,8 @@ macro_rules! include { () => {

fn check62() {
macro_rules! gen_outer_inner { () => {
macro_rules! m { () => {} }
macro_rules! m { () => {} }
macro_rules! m { () => { Wrong } }
macro_rules! m { () => { Right } }
}}
gen_outer_inner!();

Expand All @@ -268,7 +276,7 @@ macro_rules! include { () => {
fn check63() {
macro_rules! gen_gen_outer_inner { () => {
gen_outer!();
macro_rules! m { () => {} }
macro_rules! m { () => { Right } }
}}
gen_gen_outer_inner!();

Expand Down
92 changes: 46 additions & 46 deletions src/test/ui/macros/restricted-shadowing-legacy.stderr
@@ -1,19 +1,19 @@
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:93:13
--> $DIR/restricted-shadowing-legacy.rs:101:13
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:80:9
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:89:9
--> $DIR/restricted-shadowing-legacy.rs:97:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -23,21 +23,21 @@ LL | include!();
= note: macro-expanded macros do not shadow

error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:131:42
--> $DIR/restricted-shadowing-legacy.rs:139:42
|
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
| ^
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:80:9
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:127:9
--> $DIR/restricted-shadowing-legacy.rs:135:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -47,21 +47,21 @@ LL | include!();
= note: macro-expanded macros do not shadow

error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:140:9
--> $DIR/restricted-shadowing-legacy.rs:148:9
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:80:9
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:136:9
--> $DIR/restricted-shadowing-legacy.rs:144:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -71,93 +71,93 @@ LL | include!();
= note: macro-expanded macros do not shadow

error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:156:9
--> $DIR/restricted-shadowing-legacy.rs:164:9
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:80:9
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:77:9
--> $DIR/restricted-shadowing-legacy.rs:85:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | macro_rules! m { () => { Wrong } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow

error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:172:13
--> $DIR/restricted-shadowing-legacy.rs:180:13
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:80:9
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:77:9
--> $DIR/restricted-shadowing-legacy.rs:85:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | macro_rules! m { () => { Wrong } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow

error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:210:42
--> $DIR/restricted-shadowing-legacy.rs:218:42
|
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
| ^
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:80:9
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:77:9
--> $DIR/restricted-shadowing-legacy.rs:85:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | macro_rules! m { () => { Wrong } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow

error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:224:9
--> $DIR/restricted-shadowing-legacy.rs:232:9
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:80:9
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:219:13
--> $DIR/restricted-shadowing-legacy.rs:227:13
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -167,21 +167,21 @@ LL | include!();
= note: macro-expanded macros do not shadow

error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:254:42
--> $DIR/restricted-shadowing-legacy.rs:262:42
|
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
| ^
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:80:9
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:249:13
--> $DIR/restricted-shadowing-legacy.rs:257:13
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down

0 comments on commit 9beb5c3

Please sign in to comment.