Closed
Description
macro_rules! expr {
($a:expr) => ($a)
}
macro_rules! str_tts {
($b:tt) => {
expr!(stringify!($b))
}
}
fn main () {
// This works ("$ c").
let x = expr!(stringify!($c));
// This errors with "unknown macro variable `c`".
let y = str_tts!($c);
println!("{} {}", x, y);
}
It seems that while expanding the str_tts
invocation, the $c
token ends up being interpreted as a macro variable, even though it should be packaged in a tt
non-terminal.
Also to be noted is the fact that stringify!($c)
produces "$ c"
, implying there are two tokens, a dollar sign and an identifier, whereas when passed to a macro_rules
macro, it "fits" in a single tt
.
Maybe it was a bad idea to ever have a $
token and a $var
token type, the $
token would suffice, although macro_rules
expansion may become more complicated.