Closed
Description
#[macro_export]
macro_rules! separator {
() => { "/" };
}
#[macro_export]
macro_rules! concat_separator {
( $e:literal, $($other:literal),+ ) => {
concat!($e, $crate::separator!(), $crate::concat_separator!($($other),+))
};
( $e:literal ) => {
$e
}
}
fn main() {
println!("{}", concat_separator!(2, 3, 4))
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0433]: failed to resolve: could not find `separator` in `$crate`
--> src/main.rs:9:29
|
9 | concat!($e, $crate::separator!(), $crate::concat_separator!($($other),+))
| ^^^^^^^^^ could not find `separator` in `$crate`
...
17 | println!("{}", concat_separator!(2, 3, 4))
| -------------------------- in this macro invocation
error[E0433]: failed to resolve: could not find `concat_separator` in `$crate`
--> src/main.rs:9:51
|
9 | concat!($e, $crate::separator!(), $crate::concat_separator!($($other),+))
| ^^^^^^^^^^^^^^^^ could not find `concat_separator` in `$crate`
...
17 | println!("{}", concat_separator!(2, 3, 4))
| -------------------------- in this macro invocation
If either the recursion (playground) or the concat!
is removed (playground), this compiles exactly as expected. Additionally, if I explicitly name my crate, it works as expected, but would be vulnerable to crate renames in user code (can't reproduce in playground because it doesn't build a library).