Rollup merge of #55292 - estebank:macro-eof, r=pnkfelix
Macro diagnostics tweaks Fix #30128, fix #10951 by adding an appropriate span to the diagnostic. Fix #26288 by suggesting adding semicolon to macro call.
This commit is contained in:
commit
c6cd57dd86
11 changed files with 123 additions and 35 deletions
|
|
@ -3,12 +3,11 @@ error: macro expansion ignores token `;` and any following
|
|||
|
|
||||
LL | () => ( String ; ); //~ ERROR macro expansion ignores token `;`
|
||||
| ^
|
||||
|
|
||||
note: caused by the macro expansion here; the usage of `t!` is likely invalid in type context
|
||||
--> $DIR/issue-30007.rs:16:16
|
||||
|
|
||||
...
|
||||
LL | let i: Vec<t!()>;
|
||||
| ^^^^
|
||||
| ---- caused by the macro expansion here
|
||||
|
|
||||
= note: the usage of `t!` is likely invalid in type context
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -3,36 +3,33 @@ error: macro expansion ignores token `;` and any following
|
|||
|
|
||||
LL | () => ( i ; typeof ); //~ ERROR expected expression, found reserved keyword `typeof`
|
||||
| ^
|
||||
|
|
||||
note: caused by the macro expansion here; the usage of `m!` is likely invalid in type context
|
||||
--> $DIR/macro-context.rs:20:12
|
||||
|
|
||||
...
|
||||
LL | let a: m!();
|
||||
| ^^^^
|
||||
| ---- caused by the macro expansion here
|
||||
|
|
||||
= note: the usage of `m!` is likely invalid in type context
|
||||
|
||||
error: macro expansion ignores token `typeof` and any following
|
||||
--> $DIR/macro-context.rs:13:17
|
||||
|
|
||||
LL | () => ( i ; typeof ); //~ ERROR expected expression, found reserved keyword `typeof`
|
||||
| ^^^^^^
|
||||
|
|
||||
note: caused by the macro expansion here; the usage of `m!` is likely invalid in expression context
|
||||
--> $DIR/macro-context.rs:21:13
|
||||
|
|
||||
...
|
||||
LL | let i = m!();
|
||||
| ^^^^
|
||||
| ---- caused by the macro expansion here
|
||||
|
|
||||
= note: the usage of `m!` is likely invalid in expression context
|
||||
|
||||
error: macro expansion ignores token `;` and any following
|
||||
--> $DIR/macro-context.rs:13:15
|
||||
|
|
||||
LL | () => ( i ; typeof ); //~ ERROR expected expression, found reserved keyword `typeof`
|
||||
| ^
|
||||
|
|
||||
note: caused by the macro expansion here; the usage of `m!` is likely invalid in pattern context
|
||||
--> $DIR/macro-context.rs:23:9
|
||||
|
|
||||
...
|
||||
LL | m!() => {}
|
||||
| ^^^^
|
||||
| ---- caused by the macro expansion here
|
||||
|
|
||||
= note: the usage of `m!` is likely invalid in pattern context
|
||||
|
||||
error: expected expression, found reserved keyword `typeof`
|
||||
--> $DIR/macro-context.rs:13:17
|
||||
|
|
|
|||
7
src/test/ui/macros/macro-in-expression-context-2.rs
Normal file
7
src/test/ui/macros/macro-in-expression-context-2.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
macro_rules! empty { () => () }
|
||||
|
||||
fn main() {
|
||||
match 42 {
|
||||
_ => { empty!() }
|
||||
};
|
||||
}
|
||||
8
src/test/ui/macros/macro-in-expression-context-2.stderr
Normal file
8
src/test/ui/macros/macro-in-expression-context-2.stderr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
error: expected expression, found `<eof>`
|
||||
--> $DIR/macro-in-expression-context-2.rs:5:16
|
||||
|
|
||||
LL | _ => { empty!() }
|
||||
| ^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
15
src/test/ui/macros/macro-in-expression-context.fixed
Normal file
15
src/test/ui/macros/macro-in-expression-context.fixed
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// run-rustfix
|
||||
|
||||
macro_rules! foo {
|
||||
() => {
|
||||
assert_eq!("A", "A");
|
||||
assert_eq!("B", "B");
|
||||
}
|
||||
//~^^ ERROR macro expansion ignores token `assert_eq` and any following
|
||||
//~| NOTE the usage of `foo!` is likely invalid in expression context
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo!();
|
||||
//~^ NOTE caused by the macro expansion here
|
||||
}
|
||||
15
src/test/ui/macros/macro-in-expression-context.rs
Normal file
15
src/test/ui/macros/macro-in-expression-context.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// run-rustfix
|
||||
|
||||
macro_rules! foo {
|
||||
() => {
|
||||
assert_eq!("A", "A");
|
||||
assert_eq!("B", "B");
|
||||
}
|
||||
//~^^ ERROR macro expansion ignores token `assert_eq` and any following
|
||||
//~| NOTE the usage of `foo!` is likely invalid in expression context
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo!()
|
||||
//~^ NOTE caused by the macro expansion here
|
||||
}
|
||||
15
src/test/ui/macros/macro-in-expression-context.stderr
Normal file
15
src/test/ui/macros/macro-in-expression-context.stderr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
error: macro expansion ignores token `assert_eq` and any following
|
||||
--> $DIR/macro-in-expression-context.rs:6:9
|
||||
|
|
||||
LL | assert_eq!("B", "B");
|
||||
| ^^^^^^^^^
|
||||
...
|
||||
LL | foo!()
|
||||
| ------- help: you might be missing a semicolon here: `;`
|
||||
| |
|
||||
| caused by the macro expansion here
|
||||
|
|
||||
= note: the usage of `foo!` is likely invalid in expression context
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -3,12 +3,11 @@ error: macro expansion ignores token `,` and any following
|
|||
|
|
||||
LL | , //~ ERROR macro expansion ignores token `,`
|
||||
| ^
|
||||
|
|
||||
note: caused by the macro expansion here; the usage of `ignored_item!` is likely invalid in item context
|
||||
--> $DIR/macro-incomplete-parse.rs:31:1
|
||||
|
|
||||
...
|
||||
LL | ignored_item!();
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
| ---------------- caused by the macro expansion here
|
||||
|
|
||||
= note: the usage of `ignored_item!` is likely invalid in item context
|
||||
|
||||
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `,`
|
||||
--> $DIR/macro-incomplete-parse.rs:22:14
|
||||
|
|
@ -24,12 +23,11 @@ error: macro expansion ignores token `,` and any following
|
|||
|
|
||||
LL | () => ( 1, 2 ) //~ ERROR macro expansion ignores token `,`
|
||||
| ^
|
||||
|
|
||||
note: caused by the macro expansion here; the usage of `ignored_pat!` is likely invalid in pattern context
|
||||
--> $DIR/macro-incomplete-parse.rs:36:9
|
||||
|
|
||||
...
|
||||
LL | ignored_pat!() => (),
|
||||
| ^^^^^^^^^^^^^^
|
||||
| -------------- caused by the macro expansion here
|
||||
|
|
||||
= note: the usage of `ignored_pat!` is likely invalid in pattern context
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue