You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=aa236bae17b94446cb3d4cfd5fa13c5bmacro_rules! m {() => {};}fnmain(){let _ = m![];}
Current output
error: macro expansion ends with an incomplete expression: expected expression
--> src/main.rs:6:13
|
2 | () => {};| -- in this macro arm
...
6 |let _ = m![];| ^^^^ expected expression
|
= note: the macro call doesn't expand to an expression, but it can expand to a statementhelp: add `;` to interpret the expansion as a statement |6 | let _ = m![];; | +
Desired output
error: macro expansion ends with an incomplete expression: expected expression
--> src/main.rs:6:13
|
2 | () => {};| -- in this macro arm
...
6 |let _ = m![];| ^^^^ expected expression
|
= note: the macro call doesn't expand to an expression, but it can expand to a statementhelp: return an expression from the macro expansion |2 | () => { /* expression */ }; | ~++++++++++++++++++~
Rationale and extra context
The current suggestion adds a semicolon before the existing semicolon, which should at least be detected and, in that case, the current help:-line should be suppressed. One could add a specialized help-suggestion as in the desired output above, but that's not really that relevant. So:
if there is a macro assigned to a let, I would alter the existing suggestion as mentioned above.
Other cases
Suggestion if there is a missing semicolon
Interestingly, the suggestion is kind of correct, if the code is invalid (missing semicolon):
macro_rules! m {() => {};}fnmain(){let _ = m![]}
But even then, the actual suggestion is not that helpful:
error: expected `;`, found `}`
--> src/main.rs:6:17
|
6 | let _ = m![]
| ^ help: add `;` here
7 | }
| - unexpected token
error: macro expansion ends with an incomplete expression: expected expression
--> src/main.rs:6:13
|
2 | () => {};
| -- in this macro arm
...
6 | let _ = m![]
| ^^^^ expected expression
|
= note: the macro call doesn't expand to an expression, but it can expand to a statement
help: add `;` to interpret the expansion as a statement
|
6 | let _ = m![];
| +
Code
Current output
Desired output
Rationale and extra context
The current suggestion adds a semicolon before the existing semicolon, which should at least be detected and, in that case, the current
help:
-line should be suppressed. One could add a specialized help-suggestion as in the desired output above, but that's not really that relevant. So:if there is a macro assigned to a
let
, I would alter the existing suggestion as mentioned above.Other cases
Suggestion if there is a missing semicolon
Interestingly, the suggestion is kind of correct, if the code is invalid (missing semicolon):But even then, the actual suggestion is not that helpful:
Rust Version
Anything else?
No response
The text was updated successfully, but these errors were encountered: