Closed
Description
Hello. I have just started studying rust (and macros), so may not understand fully how it works.
macro_rules! new_bind {
($t:ident, $f:expr) => {
let t = $f;
println!("3. t = {}", t);
};
}
macro_rules! existing_ident {
($t:ident, $f:expr) => {
$t = $f;
println!("1. t = {}", $t);
};
}
fn main() {
let mut t = 0;
existing_ident!(t, 1);
println!("2. t = {}", t);
new_bind!(t, 2);
println!("4. t = {}", t);
}
This code produces following ouptut:
1. t = 1
2. t = 1
3. t = 2
4. t = 1
While I expect following output (also looking at cargo expand
results), because new_bind!
macro introduces new let binding in the same scope:
1. t = 1
2. t = 1
3. t = 2
4. t = 2
I have found similar issues, but am not sure if they are the same.