Cannot macro_use a macro that uses an internal macro

a40a49f
Opened by Sean McArthur at 2024-05-28 02:50:38

For instance, trying to use the log crate:

#[macro_use(debug)] extern crate log;

fn main() {
    debug!("hello");
}

Errors with:

<log macros>:4:1: 4:4 error: macro undefined: 'log!'
<log macros>:4 log ! ( $ crate:: LogLevel:: Debug , $ ( $ arg ) * ) ; )

If you import the log macro also, all is well. In this case, that's possible. However, a crate that has an internal macro for sanity, and not to be exported, is stuck.

  1. Triage: as far as I know, this is still true today. I'm not sure how it would be fixed though.

    Steve Klabnik at 2017-01-03 17:40:04

  2. Also occurs when using #![feature(use_extern_macros)]. cc #35896

    Andy Russell at 2017-07-16 18:22:33

  3. I believe that #[macro_export(local_inner_macros)] addresses this issue. @seanmonstar what do you think?

    Steve Klabnik at 2018-10-31 13:59:01

  4. This is also fixed by the $crate prefix, right?

    Erich Gubler at 2019-04-02 18:44:44

  5. By the way, if #[macro_use]/#[macro_export] is not allowed for your INTERNAL macro (in case if you use internal macro in already 'pro-macro' project/sub-project) the following workaround work OK for me:

    1. #[macro_use] #[path = "./compile_log_macros.rs"] // !!! BUT RustRover does NOT pick up macros !!! mod compile_log_macros;

    2. include!("./compile_log_macros.rs"); // Works excellent and RustRover picks up macros successfully.

    odisseylm at 2024-05-28 02:50:38