Expanded colons not allowed to match in macros?

⚓ Rust    📅 2026-01-16    👤 surdeus    👁️ 1      

surdeus

macro_rules! spam {
    (spam: { $($t:tt)* }) => { stringify!($($t)*) };
}

macro_rules! super_spam {
    ($x:ident) => { spam: { $x $x $x } };
}

fn main() {
    // Doesn't work:
    println!(spam! { super_spam!(spam) });
}

(Playground)

Trying to do something like in downcast-rs.

Edit: The expanded colon I said refers to the one in the definition of super_spam!

4 posts - 3 participants

Read full topic

🏷️ Rust_feed