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

cargo doc doesn't pass --cfg doc to rustc #8601

Closed
jmillikin opened this issue Aug 8, 2020 · 2 comments
Closed

cargo doc doesn't pass --cfg doc to rustc #8601

jmillikin opened this issue Aug 8, 2020 · 2 comments
Labels
C-bug Category: bug

Comments

@jmillikin
Copy link

Problem
PR rust-lang/rust#53076 added support for #[cfg(doc)], which conditionally enables code when being built for documentation. This cfg is set by rustdoc when parsing a module, but is not set by Cargo when running rustc prior to running rustdoc.

This causes confusing failures to document code when the current platform can't build it, but should be able to document it.

Steps
Given this library:

pub struct T {}

impl T {
    pub const SOME_CONST: u32 = match () {
        #[cfg(target_os = "linux")] _ => 1,
        #[cfg(target_os = "freebsd")] _ => 2,
        #[cfg(doc)] _ => 3,
    };
}

A macOS machine should be able to run cargo doc to build docs, even though the library doesn't support that platform. Currently this fails

To confirm that this is caused by a bad rustc argv, invoke Cargo with RUSTFLAGS="--cfg doc" cargo doc and observe that it builds the docs successfully.

Possible Solution(s)
The best solution would be to pass --cfg doc to rustc when building docs.

Notes

Output of cargo version:

$ cargo --version
cargo 1.47.0-nightly (1653f3546 2020-08-04)
@jmillikin
Copy link
Author

Proposed fix: #8602

@jmillikin
Copy link
Author

Closing; per discussion in #8602, this won't be possible to change without breaking backwards compatibility (and it's unclear whether changing it would even be correct).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

1 participant