Skip to content

redundant_semicolons gets confused by macros #142143

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

Open
matthiaskrgr opened this issue Jun 7, 2025 · 0 comments
Open

redundant_semicolons gets confused by macros #142143

matthiaskrgr opened this issue Jun 7, 2025 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Using the following flags

--force-warn redundant_semicolons

this code:

macro_rules! m {
    ($stmt:stmt) => { #[allow(bad_style)] $stmt }
}

fn main() {
    m!(;);
}

caused the following diagnostics:

    Checking _snippet_238 v0.1.0 (/tmp/icemaker_global_tempdir.VQhomPU3g4RT/icemaker_clippyfix_tempdir.OwDhgUUlGTjy/_snippet_238)
warning: unnecessary trailing semicolon
 --> src/main.rs:2:43
  |
2 |     ($stmt:stmt) => { #[allow(bad_style)] $stmt }
  |                                           ^^^^^ help: remove this semicolon
...
6 |     m!(;);
  |     ----- in this macro invocation
  |
  = note: requested on the command line with `--force-warn redundant-semicolons`
  = note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: `_snippet_238` (bin "_snippet_238") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s

However after applying these diagnostics, the resulting code:

macro_rules! m {
    ($stmt:stmt) => { #[allow(bad_style)]  }
}

fn main() {
    m!(;);
}

no longer compiled:

    Checking _snippet_238 v0.1.0 (/tmp/icemaker_global_tempdir.VQhomPU3g4RT/icemaker_clippyfix_tempdir.OwDhgUUlGTjy/_snippet_238)
error: macro expansion ends with an incomplete expression: expected expression
 --> src/main.rs:2:42
  |
2 |     ($stmt:stmt) => { #[allow(bad_style)]  }
  |                                          ^ expected expression

error: could not compile `_snippet_238` (bin "_snippet_238") due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_snippet_238` (bin "_snippet_238" test) due to 1 previous error

Version:

rustc 1.89.0-nightly (44f415c1d 2025-06-06)
binary: rustc
commit-hash: 44f415c1d617ebc7b931a243b7b321ef8a6ca47c
commit-date: 2025-06-06
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

@matthiaskrgr matthiaskrgr added the C-bug Category: This is a bug. label Jun 7, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 7, 2025
@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. labels Jun 7, 2025
@matthiaskrgr matthiaskrgr changed the title redundant_semicolons gets confused by nacros redundant_semicolons gets confused by macros Jun 7, 2025
@matthiaskrgr matthiaskrgr added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Jun 7, 2025
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 A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants