// 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
// 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
#![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!()
}
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
}
}
fn check22() {
- macro_rules! m { () => {} }
+ macro_rules! m { () => { Wrong } }
- macro_rules! m { () => {} }
+ macro_rules! m { () => { Right } }
m!(); // OK
}
fn check39() {
gen_outer!();
- macro_rules! m { () => {} }
+ macro_rules! m { () => { Right } }
m!(); // OK
}
gen_outer!();
macro_rules! gen_inner_invoc { () => {
- macro_rules! m { () => {} }
+ macro_rules! m { () => { Right } }
m!(); // OK
}}
gen_inner_invoc!();
fn check59() {
gen_outer!();
- macro_rules! m { () => {} }
+ macro_rules! m { () => { Right } }
gen_invoc!(); // OK
}
gen_outer!();
macro_rules! gen_inner_gen_invoc { () => {
- macro_rules! m { () => {} }
+ macro_rules! m { () => { Right } }
gen_invoc!(); // OK
}}
gen_inner_gen_invoc!();
fn check34() {
macro_rules! gen_outer_inner { () => {
- macro_rules! m { () => {} }
- macro_rules! m { () => {} }
+ macro_rules! m { () => { Wrong } }
+ macro_rules! m { () => { Right } }
}}
gen_outer_inner!();
fn check35() {
macro_rules! gen_gen_outer_inner { () => {
gen_outer!();
- macro_rules! m { () => {} }
+ macro_rules! m { () => { Right } }
}}
gen_gen_outer_inner!();
fn check62() {
macro_rules! gen_outer_inner { () => {
- macro_rules! m { () => {} }
- macro_rules! m { () => {} }
+ macro_rules! m { () => { Wrong } }
+ macro_rules! m { () => { Right } }
}}
gen_outer_inner!();
fn check63() {
macro_rules! gen_gen_outer_inner { () => {
gen_outer!();
- macro_rules! m { () => {} }
+ macro_rules! m { () => { Right } }
}}
gen_gen_outer_inner!();
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 { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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 { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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 { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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 { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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 { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
// 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
#![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() {
}
fn check5() {
- macro m() {}
+ macro m() { Wrong }
{
#[rustc_transparent_macro]
macro gen_inner_invoc() {
- macro m() {}
+ macro m() { Right }
m!(); // OK
}
gen_inner_invoc!();
}
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!();
}
fn check10() {
- macro m() {}
+ macro m() { Wrong }
{
- macro m() {}
+ macro m() { Right }
gen_invoc!(); // OK
}
}
}
fn check22() {
- macro m() {}
+ macro m() { Wrong }
{
- macro m() {}
+ macro m() { Right }
m!(); // OK
}
}
fn check39() {
gen_outer!();
{
- macro m() {}
+ macro m() { Right }
m!(); // OK
}
}
{
#[rustc_transparent_macro]
macro gen_inner_invoc() {
- macro m() {}
+ macro m() { Right }
m!(); // OK
}
gen_inner_invoc!();
fn check59() {
gen_outer!();
{
- macro m() {}
+ macro m() { Right }
gen_invoc!(); // OK
}
}
{
#[rustc_transparent_macro]
macro gen_inner_gen_invoc() {
- macro m() {}
+ macro m() { Right }
gen_invoc!(); // OK
}
gen_inner_gen_invoc!();
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
| ^
| ----------- 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() {}
| ^^^^^^^^^^^^
= 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
| ^
| ----------- 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() {}
| ^^^^^^^^^^^^
= 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
| ^
| ----------- 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() {}
| ^^^^^^^^^^^^
= 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
| ^
| ----------- 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
| ^
| ----------- 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
| ^
| ----------- 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