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

neither RUSTFLAGS nor RUSTDOCFLAGS passed to rustdoc by "cargo test --doc" #13697

Closed
decathorpe opened this issue Apr 3, 2024 · 3 comments
Closed
Labels
A-doctests Area: rustdoc --test S-triage Status: This issue is waiting on initial triage.

Comments

@decathorpe
Copy link
Contributor

We're running cargo test for many Rust crates we package in Fedora Linux to ensure they work in our environment and on all CPU architectures that we support. We define RUSTFLAGS="--cap-lints=warn" (among other things) to avoid crates starting to fail to build due to things like #![deny(warnings)] with newer Rust versions that add new lints.

Passing "--cap-lints=warn" with RUSTFLAGS works fine for normal library code and test code, but it doesn't get applied to rustdoc when it checks / compiles doctests, and this often causes problems because many crates use #![deny(warnings)] for their doctests / example code in doc comments.

I tried defining RUSTDOCFLAGS="--cap-lints=warn" in addition to having this flag already present in RUSTFLAGS, it didn't change the behaviour. I tried adding a build.rustdocflags = "--cap-lints=warn" setting to .cargo/config, and it didn't change anything either.

It appears that cargo test --doc isn't passing either RUSTFLAGS or RUSTDOCFLAGS to rustdoc correctly.

Good test cases might be the rand_core or pyo3 crates, which fail to build doctests with latest Rust stable due to deny(warnings).


Originally filed here:
rust-lang/rust#123424

@weihanglo
Copy link
Member

If you have this doc comment and run either

  • RUSTDOCFLAGS="--cfg mycfg" cargo t --doc, or
  • cargo t --doc --config "build.rustdocflags='--cfg mycfg'"

it will fail as expected.

/// ```
/// #[cfg(mycfg)]
/// assert!(false, "--cfg mycfg");
/// ```
pub fn f() {}

Cargo basically passes the user-provided flags as-is to rustc/rustdoc, so I wonder if rustdoc hijacks lint-level flags for something special. Needs some investigations...

@weihanglo weihanglo added A-doctests Area: rustdoc --test S-triage Status: This issue is waiting on initial triage. labels Apr 3, 2024
@weihanglo
Copy link
Member

Found this: rust-lang/rust#67533. So this is a duplicate of that.

@weihanglo
Copy link
Member

Close in favor of rust-lang/rust#67533. Thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-doctests Area: rustdoc --test S-triage Status: This issue is waiting on initial triage.
Projects
Development

No branches or pull requests

2 participants