Rollup merge of #73936 - zachlute:rustdoc-optflagmulti, r=jyn514

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 #8373](https://github.com/rust-lang/cargo/issues/8373), in [Cargo PR #8422](https://github.com/rust-lang/cargo/pull/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.
This commit is contained in:
Yuki Okushi 2021-07-12 04:31:58 +09:00 committed by GitHub
commit 25dda3647e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 19 deletions

View File

@ -269,9 +269,9 @@ fn opts() -> Vec<RustcOptGroup> {
let stable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::stable;
let unstable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::unstable;
vec![
stable("h", |o| o.optflag("h", "help", "show this help message")),
stable("V", |o| o.optflag("V", "version", "print rustdoc's version")),
stable("v", |o| o.optflag("v", "verbose", "use verbose output")),
stable("h", |o| o.optflagmulti("h", "help", "show this help message")),
stable("V", |o| o.optflagmulti("V", "version", "print rustdoc's version")),
stable("v", |o| o.optflagmulti("v", "verbose", "use verbose output")),
stable("r", |o| {
o.optopt("r", "input-format", "the input type of the specified file", "[rust]")
}),
@ -309,14 +309,14 @@ fn opts() -> Vec<RustcOptGroup> {
)
}),
stable("plugins", |o| o.optmulti("", "plugins", "removed", "PLUGINS")),
stable("no-default", |o| o.optflag("", "no-defaults", "don't run the default passes")),
stable("no-default", |o| o.optflagmulti("", "no-defaults", "don't run the default passes")),
stable("document-private-items", |o| {
o.optflag("", "document-private-items", "document private items")
o.optflagmulti("", "document-private-items", "document private items")
}),
unstable("document-hidden-items", |o| {
o.optflag("", "document-hidden-items", "document items that have doc(hidden)")
o.optflagmulti("", "document-hidden-items", "document items that have doc(hidden)")
}),
stable("test", |o| o.optflag("", "test", "run code examples as tests")),
stable("test", |o| o.optflagmulti("", "test", "run code examples as tests")),
stable("test-args", |o| {
o.optmulti("", "test-args", "arguments to pass to the test runner", "ARGS")
}),
@ -386,7 +386,7 @@ fn opts() -> Vec<RustcOptGroup> {
o.optopt("", "markdown-playground-url", "URL to send code snippets to", "URL")
}),
stable("markdown-no-toc", |o| {
o.optflag("", "markdown-no-toc", "don't include table of contents")
o.optflagmulti("", "markdown-no-toc", "don't include table of contents")
}),
stable("e", |o| {
o.optopt(
@ -412,13 +412,13 @@ fn opts() -> Vec<RustcOptGroup> {
)
}),
unstable("display-warnings", |o| {
o.optflag("", "display-warnings", "to print code warnings when testing doc")
o.optflagmulti("", "display-warnings", "to print code warnings when testing doc")
}),
stable("crate-version", |o| {
o.optopt("", "crate-version", "crate version to print into documentation", "VERSION")
}),
unstable("sort-modules-by-appearance", |o| {
o.optflag(
o.optflagmulti(
"",
"sort-modules-by-appearance",
"sort modules by where they appear in the program, rather than alphabetically",
@ -495,7 +495,7 @@ fn opts() -> Vec<RustcOptGroup> {
o.optopt("", "json", "Configure the structure of JSON diagnostics", "CONFIG")
}),
unstable("disable-minification", |o| {
o.optflag("", "disable-minification", "Disable minification applied on JS files")
o.optflagmulti("", "disable-minification", "Disable minification applied on JS files")
}),
stable("warn", |o| o.optmulti("W", "warn", "Set lint warnings", "OPT")),
stable("allow", |o| o.optmulti("A", "allow", "Set lint allowed", "OPT")),
@ -523,7 +523,7 @@ fn opts() -> Vec<RustcOptGroup> {
o.optopt("", "index-page", "Markdown file to be used as index page", "PATH")
}),
unstable("enable-index-page", |o| {
o.optflag("", "enable-index-page", "To enable generation of the index page")
o.optflagmulti("", "enable-index-page", "To enable generation of the index page")
}),
unstable("static-root-path", |o| {
o.optopt(
@ -535,7 +535,7 @@ fn opts() -> Vec<RustcOptGroup> {
)
}),
unstable("disable-per-crate-search", |o| {
o.optflag(
o.optflagmulti(
"",
"disable-per-crate-search",
"disables generating the crate selector on the search box",
@ -550,14 +550,14 @@ fn opts() -> Vec<RustcOptGroup> {
)
}),
unstable("show-coverage", |o| {
o.optflag(
o.optflagmulti(
"",
"show-coverage",
"calculate percentage of public items with documentation",
)
}),
unstable("enable-per-target-ignores", |o| {
o.optflag(
o.optflagmulti(
"",
"enable-per-target-ignores",
"parse ignore-foo for ignoring doctests on a per-target basis",
@ -582,9 +582,9 @@ fn opts() -> Vec<RustcOptGroup> {
unstable("test-builder", |o| {
o.optopt("", "test-builder", "The rustc-like binary to use as the test builder", "PATH")
}),
unstable("check", |o| o.optflag("", "check", "Run rustdoc checks")),
unstable("check", |o| o.optflagmulti("", "check", "Run rustdoc checks")),
unstable("generate-redirect-map", |o| {
o.optflag(
o.optflagmulti(
"",
"generate-redirect-map",
"Generate JSON file at the top level instead of generating HTML redirection files",
@ -598,9 +598,11 @@ fn opts() -> Vec<RustcOptGroup> {
"[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]",
)
}),
unstable("no-run", |o| o.optflag("", "no-run", "Compile doctests without running them")),
unstable("no-run", |o| {
o.optflagmulti("", "no-run", "Compile doctests without running them")
}),
unstable("show-type-layout", |o| {
o.optflag("", "show-type-layout", "Include the memory layout of types in the docs")
o.optflagmulti("", "show-type-layout", "Include the memory layout of types in the docs")
}),
]
}

View File

@ -0,0 +1,4 @@
// compile-flags: --document-private-items --document-private-items
// @has duplicate_flags/struct.Private.html
struct Private;