Skip to content

Useless suggestion for macro expansion starting with ; used in expression position #109237

Closed
@CAD97

Description

@CAD97

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 ;.

[rustexplorer]

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions