-
Couldn't load subscription status.
- Fork 13.9k
Closed
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
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.
Metadata
Metadata
Assignees
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)