You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
macro_rules! expr {($a:expr) => ($a)}macro_rules! str_tts {($b:tt) => {
expr!(stringify!($b))}}fnmain(){// 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.
The text was updated successfully, but these errors were encountered:
eddyb
added
the
A-macros
Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
label
Sep 15, 2015
stringify!($c), along with any other macro invocation with $foo as an argument, now errors with "error: unknown macro variable c", so this can either be closed or renamed/repurposed; a decision as to what we want would be nice.
Not sure what I was talking about before, but today the following error is reported. I believe this indicates that $c is now two tokens, so accepting a single tt doesn't work. @jseyfried Can you confirm that interpretation as correct?
error: no rules expected the token `c`
--> test.rs:15:23
|
15 | let y = str_tts!($c);
| ----------^- in this macro invocation
On playpen.
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 att
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 amacro_rules
macro, it "fits" in a singlett
.Maybe it was a bad idea to ever have a
$
token and a$var
token type, the$
token would suffice, althoughmacro_rules
expansion may become more complicated.The text was updated successfully, but these errors were encountered: