Trailing semicolon silently ignored in expr macro
0c0aa63
Opened by mahkoh at
fn main() {
macro_rules! a {
($e:expr) => { $e; }
}
a!(true)
}
Error: Expected (), found bool
But:
fn main() {
macro_rules! a {
($e:expr) => { $e; }
}
a!(true); // <-- semicolon
}
does not warn that the ; is ignored.
So either
- there should be a warning that the
;has no effect in the macro, or - the
;inside the macro should turn the expression into().
I'm not sure there should be a warning for use of a semicolon in an expression expansion. The problem is fixed when you write
($e: expr) => {{ $e; }}which indicates a block expansion.So the semicolon is silently ignored, but putting something after it throws a helpful error:
($e:expr) => { $e; blahblah }gives the error "macro expansion ignores tokenblahblahand any following".Michael Rosenberg at 2016-05-30 05:35:30
cc me
Jeffrey Seyfried at 2016-06-10 04:10:41
Progress towards fixing this issue is tracked in https://github.com/rust-lang/rust/issues/79813
Aaron Hill at 2020-12-08 02:06:28