Closed
Description
Users who want a macro that expands to a collection items are required to wrap the RHS in {}
in order to get them to expand to a whole block. However, if they fail to do so, they unexpectedly just get the first item of the block, rather than an error message.
macro_rules! print_if_nonzero(
($msg:expr, $($field:ident),*) => ( /*{*/
$(
if t.$field != 0 {
println($msg);
}
)*
/*}*/ )
)
struct T { x: int, y: int }
fn main() {
let t = T { x: 0, y: 0 };
print_if_nonzero!("hello", x, y);
}
...expands to...
fn main() { let t = T{x: 0, y: 0,}; if t.x != 0 { println("hello"); }; }