Stream: t-compiler

Topic: using `macro_rules` macros


matklad (Nov 27 2019 at 07:02, on Zulip):

My understanding is that macro_rules macros can't be imported with use, because there are some unresolved questions about macro-expansion ordering. However, I've now discovered that one can in fact use this macro, via reexport and new-style lexically scoped use. Is this a feature, or a bug?

mod macros {
    macro_rules! _my_macro {
        () => ()
    }
    pub(crate) use _my_macro as my_macro;
}

mod b {
    crate::macros::my_macro!();
    super::macros::my_macro!();
    // my_macro!();
}

cc @Vadim Petrochenkov

Vadim Petrochenkov (Nov 27 2019 at 19:30, on Zulip):

This is a direct consequence of "uniform paths", if the macro can be called, then it can be used as well.

Vadim Petrochenkov (Nov 27 2019 at 19:31, on Zulip):

Not sure what are the unresolved questions here.

matklad (Nov 27 2019 at 19:55, on Zulip):

So, useing macro_rules macros (without this hack) is not allowed simply because it's not implemented, and not because there's some big reason not to allow it?

Matthew Jasper (Nov 27 2019 at 20:01, on Zulip):

They can't be used because they have strange scoping, not because there's a special rule for use and macros.

macro_rules! m { () => {}}

mod x {
    use m as k; // OK on 2018 - This isn't allowed on 2015 because `::m!()` isn't either.
    k!();
}
Last update: Dec 12 2019 at 01:05UTC