Skip to content

#[macro_export] stops macro's documentation tests from working #29286

Open
@Binero

Description

@Binero

Adding #[macro_export] to a macro stops it from working in documentation tests. Here's a few examples:

/// Test macro
///
/// #Examples
/// ```
/// test_macro!(TestStructure);
/// ```
#[macro_export]
macro_rules! test_macro {
    ($expression:ident) => (struct $expression);
}
#[macro_export]
/// Test macro
///
/// #Examples
/// ```
/// test_macro!(TestStructure);
/// ```
macro_rules! test_macro {
    ($expression:ident) => (struct $expression);
}

They both will yield output similar to this (using cargo):

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured

   Doc-tests macro_doc

running 1 test
test test_macro!_0 ... FAILED

failures:

---- test_macro!_0 stdout ----
    <anon>:2:5: 2:15 error: macro undefined: 'test_macro!'
<anon>:2     test_macro!(TestStructure);
             ^~~~~~~~~~
error: aborting due to previous error


failures:
    test_macro!_0

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured

thread '<unnamed>' panicked at 'Some tests failed', ../src/libtest/lib.rs:252

Removing the export makes it work fine:

/// Test macro
///
/// #Examples
/// ```
/// test_macro!(TestStructure);
/// ```
macro_rules! test_macro {
    ($expression:ident) => (struct $expression);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: Documentation tests, run by rustdocA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions