Add checks for expected macro output in restricted shadowing tests

This commit is contained in:
Vadim Petrochenkov 2018-09-08 02:50:57 +03:00
parent ae2e5aa1c7
commit 9beb5c3ef3
5 changed files with 134 additions and 116 deletions

View File

@ -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

View File

@ -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
@ -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!()
@ -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
}
@ -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
}
@ -159,7 +167,7 @@ macro_rules! include { () => {
fn check39() {
gen_outer!();
macro_rules! m { () => {} }
macro_rules! m { () => { Right } }
m!(); // OK
}
@ -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!();
@ -187,7 +195,7 @@ macro_rules! include { () => {
fn check59() {
gen_outer!();
macro_rules! m { () => {} }
macro_rules! m { () => { Right } }
gen_invoc!(); // OK
}
@ -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!();
@ -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!();
@ -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!();
@ -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!();
@ -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!();

View File

@ -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 { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -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 { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -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 { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -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 { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -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 { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -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
@ -72,15 +77,18 @@
#![feature(decl_macro, rustc_attrs)]
struct Right;
// struct Wrong; // not defined
#[rustc_transparent_macro]
macro include() {
#[rustc_transparent_macro]
macro gen_outer() {
macro m() {}
macro m() { Wrong }
}
#[rustc_transparent_macro]
macro gen_inner() {
macro m() {}
macro m() { Right }
}
#[rustc_transparent_macro]
macro gen_invoc() {
@ -102,11 +110,11 @@ macro include() {
}
fn check5() {
macro m() {}
macro m() { Wrong }
{
#[rustc_transparent_macro]
macro gen_inner_invoc() {
macro m() {}
macro m() { Right }
m!(); // OK
}
gen_inner_invoc!();
@ -114,11 +122,11 @@ macro include() {
}
fn check9() {
macro m() {}
macro m() { Wrong }
{
#[rustc_transparent_macro]
macro gen_inner_gen_invoc() {
macro m() {}
macro m() { Right }
gen_invoc!(); // OK
}
gen_inner_gen_invoc!();
@ -126,9 +134,9 @@ macro include() {
}
fn check10() {
macro m() {}
macro m() { Wrong }
{
macro m() {}
macro m() { Right }
gen_invoc!(); // OK
}
}
@ -152,9 +160,9 @@ macro include() {
}
fn check22() {
macro m() {}
macro m() { Wrong }
{
macro m() {}
macro m() { Right }
m!(); // OK
}
}
@ -170,7 +178,7 @@ macro include() {
fn check39() {
gen_outer!();
{
macro m() {}
macro m() { Right }
m!(); // OK
}
}
@ -192,7 +200,7 @@ macro include() {
{
#[rustc_transparent_macro]
macro gen_inner_invoc() {
macro m() {}
macro m() { Right }
m!(); // OK
}
gen_inner_invoc!();
@ -202,7 +210,7 @@ macro include() {
fn check59() {
gen_outer!();
{
macro m() {}
macro m() { Right }
gen_invoc!(); // OK
}
}
@ -212,7 +220,7 @@ macro include() {
{
#[rustc_transparent_macro]
macro gen_inner_gen_invoc() {
macro m() {}
macro m() { Right }
gen_invoc!(); // OK
}
gen_inner_gen_invoc!();

View File

@ -1,5 +1,5 @@
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-modern.rs:98:17
--> $DIR/restricted-shadowing-modern.rs:106:17
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^
@ -8,15 +8,15 @@ LL | include!();
| ----------- in this macro invocation
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:83:9
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
LL | macro m() { Right }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:93:9
--> $DIR/restricted-shadowing-modern.rs:101:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
@ -26,7 +26,7 @@ LL | include!();
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-modern.rs:141:33
--> $DIR/restricted-shadowing-modern.rs:149:33
|
LL | macro gen_invoc() { m!() } //~ ERROR `m` is ambiguous
| ^
@ -35,15 +35,15 @@ LL | include!();
| ----------- in this macro invocation
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:83:9
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
LL | macro m() { Right }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:137:9
--> $DIR/restricted-shadowing-modern.rs:145:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
@ -53,7 +53,7 @@ LL | include!();
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-modern.rs:150:13
--> $DIR/restricted-shadowing-modern.rs:158:13
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^
@ -62,15 +62,15 @@ LL | include!();
| ----------- in this macro invocation
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:83:9
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
LL | macro m() { Right }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:147:9
--> $DIR/restricted-shadowing-modern.rs:155:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
@ -80,7 +80,7 @@ LL | include!();
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-modern.rs:166:13
--> $DIR/restricted-shadowing-modern.rs:174:13
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^
@ -89,25 +89,25 @@ LL | include!();
| ----------- in this macro invocation
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:83:9
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
LL | macro m() { Right }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:79:9
--> $DIR/restricted-shadowing-modern.rs:87:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
LL | macro m() { Wrong }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-modern.rs:184:17
--> $DIR/restricted-shadowing-modern.rs:192:17
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^
@ -116,25 +116,25 @@ LL | include!();
| ----------- in this macro invocation
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:83:9
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
LL | macro m() { Right }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:79:9
--> $DIR/restricted-shadowing-modern.rs:87:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
LL | macro m() { Wrong }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-modern.rs:227:33
--> $DIR/restricted-shadowing-modern.rs:235:33
|
LL | macro gen_invoc() { m!() } //~ ERROR `m` is ambiguous
| ^
@ -143,18 +143,18 @@ LL | include!();
| ----------- in this macro invocation
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:83:9
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
LL | macro m() { Right }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:79:9
--> $DIR/restricted-shadowing-modern.rs:87:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
LL | macro m() { Wrong }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation