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

rustdoc --test does not respect -Zcrate-attr #138491

Open
tamird opened this issue Mar 14, 2025 · 2 comments
Open

rustdoc --test does not respect -Zcrate-attr #138491

tamird opened this issue Mar 14, 2025 · 2 comments
Labels
-Zcrate-attr Unstable option: -Zcrate-attr A-attributes Area: Attributes (`#[…]`, `#![…]`) A-CLI Area: Command-line interface (CLI) to the compiler C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@tamird
Copy link
Contributor

tamird commented Mar 14, 2025

I tried this code (what cargo new --lib generates):

pub fn add(left: u64, right: u64) -> u64 {
    left + right
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);
    }
}

I expected both rustdoc and rustdoc --test to behave identically with respect to -Zcrate-attr, but:

% rustdoc +nightly src/lib.rs -Zcrate-attr='feature(strict_provenance_lints)' -Wfuzzy_provenance_casts
% echo $?
0
% rustdoc +nightly --test src/lib.rs -Zcrate-attr='feature(strict_provenance_lints)' -Wfuzzy_provenance_casts
warning: unknown lint: `fuzzy_provenance_casts`
  |
  = note: the `fuzzy_provenance_casts` lint is unstable
  = note: see issue #130351 <https://github.com/rust-lang/rust/issues/130351> for more information
  = help: add `-Zcrate-attr="feature(strict_provenance_lints)"` to the command-line options to enable
  = note: this compiler was built on 2025-03-13; consider upgrading it if it is out of date
  = note: `#[warn(unknown_lints)]` on by default

warning: 1 warning emitted


running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (cbfdf0b01 2025-03-13)
binary: rustc
commit-hash: cbfdf0b014cb04982a9cbeec1578001001167f6e
commit-date: 2025-03-13
host: aarch64-apple-darwin
release: 1.87.0-nightly
LLVM version: 20.1.0
@tamird tamird added the C-bug Category: This is a bug. label Mar 14, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 14, 2025
@tamird tamird changed the title rustdoc --test does not respect -Zcrate-attr rustdoc --test does not respect -Zcrate-attr Mar 14, 2025
@bjorn3
Copy link
Member

bjorn3 commented Mar 14, 2025

It is possible that rustdoc respects it while parsing the crate that contains the doc tests, but doesn't respect it while compiling the doc tests themself.

@fmease fmease added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-attributes Area: Attributes (`#[…]`, `#![…]`) A-CLI Area: Command-line interface (CLI) to the compiler requires-nightly This issue requires a nightly compiler in some way. labels Mar 14, 2025
@jieyouxu jieyouxu added -Zcrate-attr Unstable option: -Zcrate-attr and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 16, 2025
@jyn514
Copy link
Member

jyn514 commented Mar 17, 2025

It is possible that rustdoc respects it while parsing the crate that contains the doc tests, but doesn't respect it while compiling the doc tests themself.

i think this is not actually a bug. to apply attributes to the generated test you can use -Zcrate-attr='doc(test(attr(feature(strict_provenance_lints))))'. see rust-lang/rfcs#3791 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Zcrate-attr Unstable option: -Zcrate-attr A-attributes Area: Attributes (`#[…]`, `#![…]`) A-CLI Area: Command-line interface (CLI) to the compiler C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants