-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Macro diagnostics tweaks #55292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Macro diagnostics tweaks #55292
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
macro_rules! empty { () => () } | ||
|
||
fn main() { | ||
match 42 { | ||
_ => { empty!() } | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dtolnay can you take a look and verify wether this suggestion is reasonable (it won't be wrong more often than not)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is one case where it'd be the wrong approach:
but the suggestion actually gets the code to compile... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this suggestion will be helpful. 👍 |
||
|
||
error: aborting due to previous error | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not peek ahead to the source text immediately following the span and see if there's a semicolon as the next character before making such an obviously inapplicable help message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're actually checking that, which makes me intrigued at why this isn't being picked up. My guess is that if spans were completely hygienic this suggestion would appear on line 13, after
typeof
. This seems to be the only edge-case caught by our tests (before I added the linked check, many other incorrect suggestions were being emitted). Given that, would you mind if we merge as is and add extra logic in a later PR?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good