Macro used in comment not visible

I'm modifying a code that used to compile ok. All of a sudden a macro stopped being visible in the scope of its doc-comment. This happens when I import code from a test script:

/// ...
/// let map = localization_vars!{ ... }
/// ...
/// 
#[macro_export]
macro_rules! localization_vars {
    // ...
}

I get:

error: cannot find macro `localization_vars` in this scope
 --> src\message_locator.rs:14:15
  |
3 |     let map = localization_vars!{
  |               ^^^^^^^^^^^^^^^^^
  |
  = note: consider importing this macro:
          recoyx_message_localization::localization_vars

I tried adding #[macro_use], yet nothing.

I also just tried this:

macro_rules! localization_vars {
    ....
}

pub use localization_vars;

This gives duplicate error.

Running test also tries to compile any example code (present in comments). But the examples are compiled as if they are written outside the current crate. So, you need to add a correct use statement (or a complete path for the macro)..

/// ...
/// use recoyx_message_localization::localization_vars; // <-- add it here
/// let map = localization_vars!{ ... }
/// ...
/// 
3 Likes

Also, if you don’t want to include the use statement in the rendered documentation, you can prefix it with #.

3 Likes