Skip to content

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

Open
@tamird

Description

@tamird

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    -Zcrate-attrUnstable option: -Zcrate-attrA-CLIArea: Command-line interface (CLI) to the compilerA-attributesArea: Attributes (`#[…]`, `#![…]`)C-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions