-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
shouldn't specify --document-private-items
twice for binaries
#8373
Labels
Comments
5 tasks
This was referenced Jun 26, 2020
Dylan-DPC-zz
pushed a commit
to Dylan-DPC-zz/rust
that referenced
this issue
Jul 11, 2021
…n514 Rustdoc: Change all 'optflag' arguments to 'optflagmulti' Because specifying these flags multiple times will never be discernibly different in functionality from specifying them a single time, there is no reason to fail and report an error to the user. This might be a slightly controversial change. it's tough to say, but it's hard to imagine a case where somebody was depending on this behavior, and doing this seem actively better for the user. This originally came up in discussion of a fix for [Cargo rust-lang#8373](rust-lang/cargo#8373), in [Cargo PR rust-lang#8422](rust-lang/cargo#8422). The issue is that Cargo will automatically add things like `--document-private-items` to binaries, because it's the only thing that makes sense there. Then some poor user comes along and adds `--document-private-items` to their `rustdoc` flags for the project and suddenly they're getting errors for specifying a flag twice and need to track down which targets to actually add it to without getting duplicates for reasons they won't understand without deep understanding of Cargo behavior. We're apparently hesitant to inspect `rustdoc` flags provided by the user directly in Cargo, because they're supposed to be opaque, so looking to see if it's already provided before adding it is evidently a non-starter. In trying to resolve that, one suggestion I came up with was to just change `rustdoc` to support passing the flag multiple times, because the user's intent should be clear and it's not *really* an error, so maybe this is a case of 'be permissive in what you accept'. This PR is an attempt to do that in a straightforward manner for purposes of discussion.
JohnTitor
added a commit
to JohnTitor/rust
that referenced
this issue
Jul 11, 2021
…n514 Rustdoc: Change all 'optflag' arguments to 'optflagmulti' Because specifying these flags multiple times will never be discernibly different in functionality from specifying them a single time, there is no reason to fail and report an error to the user. This might be a slightly controversial change. it's tough to say, but it's hard to imagine a case where somebody was depending on this behavior, and doing this seem actively better for the user. This originally came up in discussion of a fix for [Cargo rust-lang#8373](rust-lang/cargo#8373), in [Cargo PR rust-lang#8422](rust-lang/cargo#8422). The issue is that Cargo will automatically add things like `--document-private-items` to binaries, because it's the only thing that makes sense there. Then some poor user comes along and adds `--document-private-items` to their `rustdoc` flags for the project and suddenly they're getting errors for specifying a flag twice and need to track down which targets to actually add it to without getting duplicates for reasons they won't understand without deep understanding of Cargo behavior. We're apparently hesitant to inspect `rustdoc` flags provided by the user directly in Cargo, because they're supposed to be opaque, so looking to see if it's already provided before adding it is evidently a non-starter. In trying to resolve that, one suggestion I came up with was to just change `rustdoc` to support passing the flag multiple times, because the user's intent should be clear and it's not *really* an error, so maybe this is a case of 'be permissive in what you accept'. This PR is an attempt to do that in a straightforward manner for purposes of discussion.
Rustdoc PR #73936 was merged today, which means that specifying I believe this can be closed now. |
Yup, thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
PR #7593 changed Cargo to document private items for binary targets by default. This is great!
In my case, I've got a crate with two binaries and a library. The library is really only to support the binaries and the test suite. There's no need for public documentation. Instead, I want to configure the repo so that
cargo doc
documents the private items in the library. I created a.cargo/config
that specifiesbuild.rustdocflags = "--document-private-items"
. If I runcargo doc --lib
, this does the right thing (generates library documentation that includes private items). But if I just runcargo doc
, this fails because it tries to generate docs for the binaries, hits the behavior added in #7593, and passes--document-private-items
twice to rustdoc.Here's an example with a demo repo that I created to test this:
Steps
cargo doc
. Instead of generating docs, it fails.I expect you'd also run into this without a
.cargo/config
if you specifiedRUSTDOCFLAGS=--document-private-items
in the environment.Possible Solution(s): It would be nice if the auto-document-private-items behavior for binary targets checked whether
--document-private-items
is already part of the rustdoc flags before adding it.You can work around this problem by disabling docs for the binaries, using a block like this in
Cargo.toml
:Notes
Output of
cargo version
:I see the same on
cargo 1.45.0-nightly (9fcb8c1d2 2020-05-25)
. I'm on OS X 10.15.4.The text was updated successfully, but these errors were encountered: