These two snippets
macro_rules! testmacro {
( $p:pat = $($t:tt)* ) => {
testmacro!(@ {$p = $($t)*} )
};
(@{$res:pat = $some_expr:expr => $handle:block, $($t:tt)*}) => {
testmacro!(@ {$($t)*})
};
(@ {else => $else:expr$(,)?}) =>{
testmacro!(@)
};
(@)=> {1}
}
fn main(){
let val = testmacro!(
Some(mut foo) = { Some("1".to_string()) } => {
assert_eq!(foo, "1");
},
else => {2}
);
println!("{}",val)
}
and
macro_rules! testmacro {
( $p:pat = $($t:tt)* ) => {
testmacro!(@ {$p = $($t)*} )
};
(@ {else => $else:expr$(,)?}) =>{
testmacro!(@)
};
(@{$res:pat = $async_expr:expr => $handle:block, $($t:tt)*}) => {
testmacro!(@ {$($t)*})
};
(@)=> {1}
}
fn main(){
let val = testmacro!(
Some(mut foo) = { Some("1".to_string()) } => {
assert_eq!(foo, "1");
},
else => {2}
);
println!("{}",val)
}
seem to behave differently. The former would fail to compile with expected identifier, found keyword else
while the latter would compile just fine.
I'm working on this PR: feat(WIP):attributes on select! branches by drHuangMHT · Pull Request #5398 · tokio-rs/tokio · GitHub and it involves macro that uses " Incremental TT munchers". tests would fail with expected identifier, found keyword else
which is counter-intuitive because there is a branch that would catch else
as keyword.
I'm using stable-x86_64-unknown-linux-gnu rustc 1.67.0 (fc594f156 2023-01-24) and the online playground poses the same problem.