From "life before main" to "common life in main"

Just because I thought it was interesting: the weird scoping rules of macro_rules! macros very nearly allow you to implement something inventory-like without ctor, there's just one (rather silly IMO) compiler error that complains about ambiguity preventing it from actually working.

I say the error is silly because the following code does work:

macro_rules! a { () => { compile_error!("") } }
macro_rules! a { () => {} }
a!();

But this code doesn't:

macro_rules! a { ($($tt:tt)*) => { $($tt)* } }
a!(macro_rules! a { () => {} });
a!();

So I don't see why macro-generated macros shouldn't be allowed to shadow macros like manually written macros can.

1 Like