Open
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 ref
s 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