Hi guys,
I found I can macro_use a macro without marking it with macro_export, this does not match the description in this doc. the following code can compile. Any suggestion?
#[macro_use]
mod my {
//#[macro_export]
macro_rules! mym {
() => {println!("my macro")}
}
}
fn main() {
mym!();
}
Macros to be imported with #[macro_use] must be exported with #[macro_export], which is described below.
The statement applies to importing macros from extern crate sources, like:
#[macro_use]
extern crate lazy_static;
which you nowadays (since edition 2018) don't really need to care about. This does not apply to the #[macro_use] attribute declared on modules, like you did in your example. Applied to a module, it extends the scope of the macros contained in that module. It basically allows the macros to "escape" their module into the parent module. Hence you can call the macros in your parent module, without any need for #[macro_export].