resolve: Prefer macro_rules definitions to in-module macro definitions in some cases

This commit is contained in:
Vadim Petrochenkov 2018-09-27 04:49:40 +03:00
parent 4cf11765dc
commit 078fc52cbc
7 changed files with 130 additions and 23 deletions

View file

@ -45,7 +45,7 @@ mod m3 {
mod m4 {
macro_rules! m { () => {} }
use two_macros::m;
m!(); //~ ERROR ambiguous
m!();
}
fn main() {}

View file

@ -1,20 +1,3 @@
error[E0659]: `m` is ambiguous
--> $DIR/macros.rs:48:5
|
LL | m!(); //~ ERROR ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/macros.rs:46:5
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `m` could also refer to the name imported here
--> $DIR/macros.rs:47:9
|
LL | use two_macros::m;
| ^^^^^^^^^^^^^
error[E0659]: `m` is ambiguous
--> $DIR/macros.rs:26:5
|
@ -51,6 +34,6 @@ LL | use two_macros::m;
| ^^^^^^^^^^^^^
= note: macro-expanded macro imports do not shadow
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0659`.

View file

@ -0,0 +1,46 @@
// Some non-controversial subset of ambiguities "modern macro name" vs "macro_rules"
// is disambiguated to mitigate regressions from macro modularization.
// Scoping for `macro_rules` behaves like scoping for `let` at module level, in general.
#![feature(decl_macro)]
fn same_unnamed_mod() {
macro m() { 0 }
macro_rules! m { () => (()) }
m!() // OK
}
fn nested_unnamed_mod() {
macro m() { 0 }
{
macro_rules! m { () => (()) }
m!() // OK
}
}
fn nested_unnamed_mod_fail() {
macro_rules! m { () => (()) }
{
macro m() { 0 }
m!() //~ ERROR `m` is ambiguous
}
}
fn nexted_named_mod_fail() {
macro m() { 0 }
#[macro_use]
mod inner {
macro_rules! m { () => (()) }
}
m!() //~ ERROR `m` is ambiguous
}
fn main() {}

View file

@ -0,0 +1,37 @@
error[E0659]: `m` is ambiguous
--> $DIR/ambiguity-legacy-vs-modern.rs:31:9
|
LL | m!() //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/ambiguity-legacy-vs-modern.rs:26:5
|
LL | macro_rules! m { () => (()) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `m` could also refer to the name defined here
--> $DIR/ambiguity-legacy-vs-modern.rs:29:9
|
LL | macro m() { 0 }
| ^^^^^^^^^^^^^^^
error[E0659]: `m` is ambiguous
--> $DIR/ambiguity-legacy-vs-modern.rs:43:5
|
LL | m!() //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/ambiguity-legacy-vs-modern.rs:40:9
|
LL | macro_rules! m { () => (()) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `m` could also refer to the name defined here
--> $DIR/ambiguity-legacy-vs-modern.rs:36:5
|
LL | macro m() { 0 }
| ^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0659`.