Repository navigation
Open
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.L-unused_bracesLint: unused_bracesLint: unused_bracesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I tried this code:
#![allow(dead_code)]
#[derive(Debug)]
struct Foo;
#[derive(Debug)]
struct Bar;
enum SomeWrapperEnum {
Foo(Foo),
Bar(Bar),
}
macro_rules! match_all {
($on:expr, $with:ident, $body:tt, $($var:ident),*) => {
match $on {
$(
SomeWrapperEnum::$var($with) => { $body },
)*
}
}
}
macro_rules! dispatch {
($on:expr, $with:ident, $body:tt) => {
match_all!($on, $with, $body, Foo, Bar)
}
}
fn main() {
let quz = SomeWrapperEnum::Foo(Foo);
dispatch!(quz, inner, { println!("{:?}", inner) } );
}I expected to see this happen: No warnings, or applying hints from warnings improves the code.
Instead, this happened: The unused_braces lint fired, and applying the hint breaks the code.
The hint:
29 | dispatch!(quz, inner, { println!("{:?}", inner) } );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these braces
If the braces are removed:
29 | dispatch!(quz, inner, println!("{:?}", inner));
| ^ no rules expected this token in macro call
Note: Adding a semicolon after the println!() (and leaving the braces) results in no warning and the code still compiles.
I'm using stable, but reproduced on stable, debug, and nightly on play.rust-lang.org. The lint was added in #70081. I see #70717, but there are no explicit refs here. And I also see #70814, but these are not proc macros.
rustc --version --verbose:
rustc 1.44.0 (49cae5576 2020-06-01)
binary: rustc
commit-hash: 49cae55760da0a43428eba73abcb659bb70cf2e4
commit-date: 2020-06-01
host: x86_64-unknown-linux-gnu
release: 1.44.0
LLVM version: 9.0
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.L-unused_bracesLint: unused_bracesLint: unused_bracesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
lcnr commentedon Jun 6, 2020
Also happens with
unused_parens. Not sure how to fix this while still linting againstcamsteffen commentedon Jan 12, 2025
This seems to be fixed. The hint now points to the braces in the macro body which are indeed unnecessary IIUC.