Give a better error message for duplicate built-in macros
Previously, this would say no such macro existed, but this was misleading, since the macro _did_ exist, it was just already seen. - Say where the macro was previously defined - Add long-form error message
This commit is contained in:
parent
022e1fe235
commit
be2947d0b7
8 changed files with 112 additions and 8 deletions
17
src/test/ui/macros/duplicate-builtin.rs
Normal file
17
src/test/ui/macros/duplicate-builtin.rs
Normal file
|
|
@ -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 */
|
||||
}
|
||||
}
|
||||
21
src/test/ui/macros/duplicate-builtin.stderr
Normal file
21
src/test/ui/macros/duplicate-builtin.stderr
Normal file
|
|
@ -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`.
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// error-pattern: cannot find a built-in macro with name `line`
|
||||
// error-pattern: attempted to define built-in macro more than once
|
||||
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
macro_rules! unknown { () => () } //~ ERROR cannot find a built-in macro with name `unknown`
|
||||
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! line { () => () }
|
||||
macro_rules! line { () => () } //~ NOTE previously defined here
|
||||
|
||||
fn main() {
|
||||
line!();
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ error: cannot find a built-in macro with name `unknown`
|
|||
LL | macro_rules! unknown { () => () }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: cannot find a built-in macro with name `line`
|
||||
error[E0773]: attempted to define built-in macro more than once
|
||||
--> $SRC_DIR/core/src/macros/mod.rs:LL:COL
|
||||
|
|
||||
LL | / macro_rules! line {
|
||||
|
|
@ -13,6 +13,13 @@ LL | | /* compiler built-in */
|
|||
LL | | };
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: previously defined here
|
||||
--> $DIR/unknown-builtin.rs:9:1
|
||||
|
|
||||
LL | macro_rules! line { () => () }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0773`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue