When I run below code, it shows warning: unnecessary parentheses around
if condition
:
#[macro_export]
macro_rules! set_bit {
(&mut $num: expr, $n: tt, $val: tt) => {{
println!("here");
if $val {
$num |= 1 << $n;
} else {
$num &= !(1 << $n);
}
}};
(&mut $num: expr, $n: tt, ($val: tt)) => {{
if $val {
$num |= 1 << $n;
} else {
$num &= !(1 << $n);
}
}};
}
#[test]
fn test_set_bit() {
let mut bit = 2;
let disable = true;
set_bit!(&mut bit, 1, (!disable));
println!("{}", bit);
}
But if I remove the parentheses around the disable
, it shows no rules expected the token disable
, so how to fix this?