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

Stop adding the --document-private-items flag if it's already being set #8422

Closed

Conversation

zachlute
Copy link
Contributor

It is an error to define the flag twice, so if the unit is already setting that rustdoc flag, we shouldn't set it again, even if asked to do so.

Fixes #8373

It is an error to define the flag twice, so if the unit is already setting that rustdoc flag, we shouldn't set it again, even if asked to do so.
@rust-highfive
Copy link

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 26, 2020
@alexcrichton
Copy link
Member

Thanks for the PR!

Do we have a precedent though of checking for these sorts of flags in RUSTFLAGS or RUSTDOCFLAGS? AFAIK Cargo tries to treat those very opaquely without inspecting anything.

@zachlute
Copy link
Contributor Author

zachlute commented Jun 29, 2020

I don't know if there are any precedents or policies, and I don't really have strong feelings about this fix, I was just trying to do something productive with 30 minutes of time waiting on a call and this bug seemed straightforward. :)

I guess I would ask what the purpose of such a policy would be? I guess I could see the argument that we shouldn't be manipulating user-provided flags, because that would undermine the purpose of allowing them to be provided. But inspecting them?

In this case, the user has specified, "I want this flag." And then Cargo, trying to be helpful, says, "I will add this flag, because I know that you probably want it!" And it was right, I did want it, but instead of being helpful, it breaks everything. Not only that, it's not obvious (as a user) why it adds it by default for some things and not others.

So then to fix it, as a user (because presumably I added it to fix a case where it wasn't being specified by default and I wanted it) I have to either dig up the Cargo source code, or arbitrarily add it to specific targets until I get lucky or figure out that it's only the binary targets I shouldn't put it on.

It seems like any policy that would make a user jump through those kind of hoops to prevent the tool from over-helping them is at least a little bit user-hostile for no discernible benefit, in my opinion.

That said, on the other hand, you could probably make the case that this is actually a bug in rustdoc, and specifying that flag twice shouldn't be an error at all, which would nicely sidestep the whole discussion. :)

@alexcrichton
Copy link
Member

AFAIK Cargo doesn't really do much introspection of RUSTFLAGS or RUSTDOCFLAGS, intentionally so. Inspecting user-provided flags is fraught with errors because we're not parsing them, rustc or rustdoc are. While some things may seem simple (like this) it often doesn't stand well against the test of time. I would say that if this is intended to be a working feature then this should be a bug for rustdoc to accept multiple flags.

@zachlute
Copy link
Contributor Author

zachlute commented Jul 1, 2020

I went ahead and created a PR for 'fixing' this at the rustdoc level, so I guess we'll see how that goes!

rust-lang/rust#73936

@ehuss
Copy link
Contributor

ehuss commented Jan 13, 2021

Closing due to inactivity, and this seems to be blocked on the decision rust-lang/rust#73936. If it becomes clearer what happens with rustdoc, we can revisit this, but I think we will still probably prefer to avoid having Cargo inspecting rustc and rustdoc flags.

@ehuss ehuss closed this Jan 13, 2021
@jyn514
Copy link
Member

jyn514 commented Jun 30, 2021

Here's another case where this is frustrating: when there are both library and binary targets within the same package. Then RUSTDOCFLAGS=--document-private-items will give a hard error because cargo duplicates it, but leaving it out actually has different behavior because it won't document private items in the library.

I guess cargo doesn't currently have a way to pass flags to only certain crates within a package?

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 2, 2021
Document rustfmt on nightly-rustc

- Refactor the doc step for Rustdoc into a macro
- Call the macro for both rustdoc and rustfmt
- Add a `recursion_limit` macro to avoid overflow errors

This does not currently pass --document-private-items for rustfmt due to rust-lang/cargo#8422 (comment).

r? `@Mark-Simulacrum` cc `@calebcartwright`
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request 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 pull request 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo doc shouldn't specify --document-private-items twice for binaries
5 participants