Closed
Description
Code
/*
[package]
edition = "2021"
*/
macro_rules! statement {
() => {;};
}
fn main() {
let _ = statement!();
}
Current output
error: expected expression, found `;`
--> src/main.rs:7:12
|
7 | () => {;};
| ^ expected expression
...
11 | let _ = statement!();
| ------------ in this macro invocation
|
= note: the macro call doesn't expand to an expression, but it can expand to a statement
= note: this error originates in the macro `statement` (in Nightly builds, run with -Z macro-backtrace for more info)
help: add `;` to interpret the expansion as a statement
|
11 | let _ = statement!();;
| +
Desired output
error: expected expression, found `;`
--> src/main.rs:7:12
|
7 | () => {;};
| ^ expected expression
...
11 | let _ = statement!();
| ------------ in this macro invocation
|
= note: the macro call doesn't expand to an expression, but it can expand to a statement
= note: this error originates in the macro `statement` (in Nightly builds, run with -Z macro-backtrace for more info)
or perhaps
error: expected expression, found `;`
--> src/main.rs:7:12
|
7 | () => {;};
| ^ expected expression
...
11 | let _ = statement!();
| ------------ in this macro invocation
|
= note: the macro call doesn't expand to an expression, but it can expand to a statement
= note: this error originates in the macro `statement` (in Nightly builds, run with -Z macro-backtrace for more info)
help: surround the macro with `{}` to interpret the expansion as a statement
|
11 | let _ = { statement!(); };
| ++ +++
Rationale and extra context
The bad help isn't related to the choice of m!(...)
or m!{...}
(even though the former needs to be followed by ;
to be a statement and the latter doesn't, which could explain the source of the hint); m!{...}
also generates the help to add ;
.
Other cases
No response
Anything else?
$ rustc -Vv
rustc 1.70.0-nightly (ab654863c 2023-03-15)
binary: rustc
commit-hash: ab654863c3d50482f260cf862647f1fe0ff5e010
commit-date: 2023-03-15
host: x86_64-pc-windows-msvc
release: 1.70.0-nightly
LLVM version: 15.0.7
@rustbot modify labels +D-incorrect