Skip to content
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

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

Closed
CAD97 opened this issue Mar 16, 2023 · 1 comment · Fixed by #109251
Closed

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

CAD97 opened this issue Mar 16, 2023 · 1 comment · Fixed by #109251
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CAD97
Copy link
Contributor

CAD97 commented Mar 16, 2023

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

@CAD97 CAD97 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 16, 2023
@rustbot rustbot added the D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. label Mar 16, 2023
@mu001999
Copy link
Contributor

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 17, 2023
Suggest surrounding the macro with `{}` to interpret as a statement

Fixes rust-lang#109237
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 17, 2023
Suggest surrounding the macro with `{}` to interpret as a statement

Fixes rust-lang#109237
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 17, 2023
Suggest surrounding the macro with `{}` to interpret as a statement

Fixes rust-lang#109237
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 17, 2023
Suggest surrounding the macro with `{}` to interpret as a statement

Fixes rust-lang#109237
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants