-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #76143 - jyn514:duplicate-builtin-macros, r=petrochenkov
Give a better error message for duplicate built-in macros Minor follow-up to #75176 giving a better error message for duplicate builtin macros. This would have made it a little easier to debug. r? @petrochenkov
- Loading branch information
Showing
8 changed files
with
112 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
A builtin-macro was defined more than once. | ||
|
||
Erroneous code example: | ||
|
||
```compile_fail,E0773 | ||
#![feature(decl_macro)] | ||
#![feature(rustc_attrs)] | ||
#[rustc_builtin_macro] | ||
pub macro test($item:item) { | ||
/* compiler built-in */ | ||
} | ||
mod inner { | ||
#[rustc_builtin_macro] | ||
pub macro test($item:item) { | ||
/* compiler built-in */ | ||
} | ||
} | ||
``` | ||
|
||
To fix the issue, remove the duplicate declaration: | ||
|
||
``` | ||
#![feature(decl_macro)] | ||
#![feature(rustc_attrs)] | ||
#[rustc_builtin_macro] | ||
pub macro test($item:item) { | ||
/* compiler built-in */ | ||
} | ||
``` | ||
|
||
In very rare edge cases, this may happen when loading `core` or `std` twice, | ||
once with `check` metadata and once with `build` metadata. | ||
For more information, see [#75176]. | ||
|
||
[#75176]: https://github.com/rust-lang/rust/pull/75176#issuecomment-683234468 |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// compile-flags:--crate-type lib | ||
#![feature(decl_macro)] | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_builtin_macro] | ||
pub macro test($item:item) { | ||
//~^ NOTE previously defined | ||
/* compiler built-in */ | ||
} | ||
|
||
mod inner { | ||
#[rustc_builtin_macro] | ||
pub macro test($item:item) { | ||
//~^ ERROR attempted to define built-in macro more than once [E0773] | ||
/* compiler built-in */ | ||
} | ||
} |
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,21 @@ | ||
error[E0773]: attempted to define built-in macro more than once | ||
--> $DIR/duplicate-builtin.rs:13:5 | ||
| | ||
LL | / pub macro test($item:item) { | ||
LL | | | ||
LL | | /* compiler built-in */ | ||
LL | | } | ||
| |_____^ | ||
| | ||
note: previously defined here | ||
--> $DIR/duplicate-builtin.rs:6:1 | ||
| | ||
LL | / pub macro test($item:item) { | ||
LL | | | ||
LL | | /* compiler built-in */ | ||
LL | | } | ||
| |_^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0773`. |
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