-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-doctestsArea: Documentation tests, run by rustdocArea: Documentation tests, run by rustdocA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.Relevant to the rustdoc team, which will review and decide on the PR/issue.
Description
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);
}
Ltrlg
Metadata
Metadata
Assignees
Labels
A-doctestsArea: Documentation tests, run by rustdocArea: Documentation tests, run by rustdocA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.Relevant to the rustdoc team, which will review and decide on the PR/issue.
Type
Projects
Status
No status