Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Binero opened this issue Oct 24, 2015 · 2 comments
Open

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

Binero opened this issue Oct 24, 2015 · 2 comments
Labels
A-doctests Area: Documentation tests, run by rustdoc A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Binero
Copy link
Contributor

Binero commented Oct 24, 2015

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);
}
@alexcrichton alexcrichton added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Oct 25, 2015
@alexcrichton
Copy link
Member

The bug here is that rustdoc doesn't inject extern crate foo with the #[macro_use] attribute, and macros that aren't exported don't have their docs tested.

birkenfeld added a commit to birkenfeld/rust that referenced this issue May 9, 2016
@steveklabnik steveklabnik added T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. and removed T-tools labels May 18, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 24, 2017
@steveklabnik
Copy link
Member

Triage: not entirely sure this is a bug, though it is a footgun for sure.

@ehuss ehuss removed the T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. label Jan 18, 2022
@fmease fmease added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-doctests Area: Documentation tests, run by rustdoc labels Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-doctests Area: Documentation tests, run by rustdoc A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
Status: No status
Development

No branches or pull requests

6 participants