-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolve: Prefer
macro_rules
definitions to in-module macro definiti…
…ons in some cases
- Loading branch information
1 parent
4cf1176
commit 078fc52
Showing
7 changed files
with
130 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ mod m3 { | |
mod m4 { | ||
macro_rules! m { () => {} } | ||
use two_macros::m; | ||
m!(); //~ ERROR ambiguous | ||
m!(); | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |