Closed BurntSushi closed 10 years ago
Note that standard recursive macros work fine, e.g.,
macro_rules! rec_works(
() => (0);
($a:expr) => ($a);
($a:expr, $($rest:tt),*) => (
$a + rec_works!($($rest),*)
);
)
And rec_works!(1, 2, 3)
outputs 6
.
Maybe the bug here is that expanding macros within other macros is using an older environment that doesn't include the name rec
?
It's even worse than that. expand_expr
only uses the compiler built-in macros: https://github.com/rust-lang/rust/blob/master/src/libsyntax/ext/base.rs#L421
I think this might be a dupe of https://github.com/rust-lang/rust/issues/12404.
@huonw Does fixing print!(format!(...))
mean that print!(some_recursive_call!(...))
also gets fixed? I wouldn't assume so, but it might be possible depending on the implementation.
(Sorry I missed that issue. I searched for 'recursive macro' instead of 'nested macro'!)
@BurntSushi both print!
and concat_idents!
use expand_expr
, which doesn't work with non-builtin macros.
@sfackler Right. I'm referring to the recursive aspect. Wasn't sure if that would make a difference. (I just don't know enough about how macros are expanded to know. Pure guesswork on my part.)
I believe this should output the string
abc
:But I get this error:
Rust version: