Skip to content

Commit 38bfa9c

Browse files
authored
Rollup merge of rust-lang#98331 - GuillaumeGomez:rustdoc-arg-error, r=notriddle
Fix rustdoc argument error Fixes rust-lang#88756. It's a take over of rust-lang#88831. I cherry-picked the commits, fixed the merge conflict and the failing test. cc `@inashivb` `@jyn514` r? `@notriddle`
2 parents 8e52fa8 + 768129d commit 38bfa9c

File tree

12 files changed

+614
-28
lines changed

12 files changed

+614
-28
lines changed

compiler/rustc_driver/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ fn describe_codegen_flags() {
932932
print_flag_list("-C", config::CG_OPTIONS);
933933
}
934934

935-
fn print_flag_list<T>(
935+
pub fn print_flag_list<T>(
936936
cmdline_opt: &str,
937937
flag_list: &[(&'static str, T, &'static str, &'static str)],
938938
) {

src/librustdoc/config.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::path::PathBuf;
66
use std::str::FromStr;
77

88
use rustc_data_structures::fx::FxHashMap;
9+
use rustc_driver::print_flag_list;
910
use rustc_session::config::{
1011
self, parse_crate_types_from_list, parse_externs, parse_target_triple, CrateType,
1112
};
@@ -310,11 +311,15 @@ impl RenderOptions {
310311
impl Options {
311312
/// Parses the given command-line for options. If an error message or other early-return has
312313
/// been printed, returns `Err` with the exit code.
313-
pub(crate) fn from_matches(matches: &getopts::Matches) -> Result<Options, i32> {
314+
pub(crate) fn from_matches(
315+
matches: &getopts::Matches,
316+
args: Vec<String>,
317+
) -> Result<Options, i32> {
318+
let args = &args[1..];
314319
// Check for unstable options.
315320
nightly_options::check_nightly_options(matches, &opts());
316321

317-
if matches.opt_present("h") || matches.opt_present("help") {
322+
if args.is_empty() || matches.opt_present("h") || matches.opt_present("help") {
318323
crate::usage("rustdoc");
319324
return Err(0);
320325
} else if matches.opt_present("version") {
@@ -335,6 +340,21 @@ impl Options {
335340
// check for deprecated options
336341
check_deprecated_options(matches, &diag);
337342

343+
let z_flags = matches.opt_strs("Z");
344+
if z_flags.iter().any(|x| *x == "help") {
345+
print_flag_list("-Z", config::DB_OPTIONS);
346+
return Err(0);
347+
}
348+
let c_flags = matches.opt_strs("C");
349+
if c_flags.iter().any(|x| *x == "help") {
350+
print_flag_list("-C", config::CG_OPTIONS);
351+
return Err(0);
352+
}
353+
let w_flags = matches.opt_strs("W");
354+
if w_flags.iter().any(|x| *x == "help") {
355+
print_flag_list("-W", config::DB_OPTIONS);
356+
return Err(0);
357+
}
338358
if matches.opt_strs("passes") == ["list"] {
339359
println!("Available passes for running rustdoc:");
340360
for pass in passes::PASSES {

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ fn main_args(at_args: &[String]) -> MainResult {
686686

687687
// Note that we discard any distinction between different non-zero exit
688688
// codes from `from_matches` here.
689-
let options = match config::Options::from_matches(&matches) {
689+
let options = match config::Options::from_matches(&matches, args) {
690690
Ok(opts) => opts,
691691
Err(code) => {
692692
return if code == 0 {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-include ../../run-make-fulldeps/tools.mk
2+
3+
all:
4+
$(BARE_RUSTDOC) 2>&1 | sed -E 's@/nightly/|/beta/|/stable/|/1\.[0-9]+\.[0-9]+/@/$$CHANNEL/@g' | diff - output-default.stdout
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a test to verify that the default behavior of `rustdoc` is printing out help output instead of erroring out (#88756).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
rustdoc [options] <input>
2+
3+
Options:
4+
-h, --help show this help message
5+
-V, --version print rustdoc's version
6+
-v, --verbose use verbose output
7+
-w, --output-format [html]
8+
the output type to write
9+
--output PATH Which directory to place the output. This option is
10+
deprecated, use --out-dir instead.
11+
-o, --out-dir PATH which directory to place the output
12+
--crate-name NAME
13+
specify the name of this crate
14+
--crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]
15+
Comma separated list of types of crates
16+
for the compiler to emit
17+
-L, --library-path DIR
18+
directory to add to crate search path
19+
--cfg pass a --cfg to rustc
20+
--check-cfg pass a --check-cfg to rustc
21+
--extern NAME[=PATH]
22+
pass an --extern to rustc
23+
--extern-html-root-url NAME=URL
24+
base URL to use for dependencies; for example,
25+
"std=/doc" links std::vec::Vec to
26+
/doc/std/vec/struct.Vec.html
27+
--extern-html-root-takes-precedence
28+
give precedence to `--extern-html-root-url`, not
29+
`html_root_url`
30+
-C, --codegen OPT[=VALUE]
31+
pass a codegen option to rustc
32+
--document-private-items
33+
document private items
34+
--document-hidden-items
35+
document items that have doc(hidden)
36+
--test run code examples as tests
37+
--test-args ARGS
38+
arguments to pass to the test runner
39+
--test-run-directory PATH
40+
The working directory in which to run tests
41+
--target TRIPLE target triple to document
42+
--markdown-css FILES
43+
CSS files to include via <link> in a rendered Markdown
44+
file
45+
--html-in-header FILES
46+
files to include inline in the <head> section of a
47+
rendered Markdown file or generated documentation
48+
--html-before-content FILES
49+
files to include inline between <body> and the content
50+
of a rendered Markdown file or generated documentation
51+
--html-after-content FILES
52+
files to include inline between the content and
53+
</body> of a rendered Markdown file or generated
54+
documentation
55+
--markdown-before-content FILES
56+
files to include inline between <body> and the content
57+
of a rendered Markdown file or generated documentation
58+
--markdown-after-content FILES
59+
files to include inline between the content and
60+
</body> of a rendered Markdown file or generated
61+
documentation
62+
--markdown-playground-url URL
63+
URL to send code snippets to
64+
--markdown-no-toc
65+
don't include table of contents
66+
-e, --extend-css PATH
67+
To add some CSS rules with a given file to generate
68+
doc with your own theme. However, your theme might
69+
break if the rustdoc's generated HTML changes, so be
70+
careful!
71+
-Z FLAG internal and debugging options (only on nightly build)
72+
--sysroot PATH Override the system root
73+
--playground-url URL
74+
URL to send code snippets to, may be reset by
75+
--markdown-playground-url or
76+
`#![doc(html_playground_url=...)]`
77+
--display-doctest-warnings
78+
show warnings that originate in doctests
79+
--crate-version VERSION
80+
crate version to print into documentation
81+
--sort-modules-by-appearance
82+
sort modules by where they appear in the program,
83+
rather than alphabetically
84+
--default-theme THEME
85+
Set the default theme. THEME should be the theme name,
86+
generally lowercase. If an unknown default theme is
87+
specified, the builtin default is used. The set of
88+
themes, and the rustdoc built-in default, are not
89+
stable.
90+
--default-setting SETTING[=VALUE]
91+
Default value for a rustdoc setting (used when
92+
"rustdoc-SETTING" is absent from web browser Local
93+
Storage). If VALUE is not supplied, "true" is used.
94+
Supported SETTINGs and VALUEs are not documented and
95+
not stable.
96+
--theme FILES additional themes which will be added to the generated
97+
docs
98+
--check-theme FILES
99+
check if given theme is valid
100+
--resource-suffix PATH
101+
suffix to add to CSS and JavaScript files, e.g.,
102+
"light.css" will become "light-suffix.css"
103+
--edition EDITION
104+
edition to use when compiling rust code (default:
105+
2015)
106+
--color auto|always|never
107+
Configure coloring of output:
108+
auto = colorize, if output goes to a tty (default);
109+
always = always colorize output;
110+
never = never colorize output
111+
--error-format human|json|short
112+
How errors and other messages are produced
113+
--json CONFIG Configure the structure of JSON diagnostics
114+
--disable-minification
115+
Disable minification applied on JS files
116+
-A, --allow LINT Set lint allowed
117+
-W, --warn LINT Set lint warnings
118+
--force-warn LINT
119+
Set lint force-warn
120+
-D, --deny LINT Set lint denied
121+
-F, --forbid LINT Set lint forbidden
122+
--cap-lints LEVEL
123+
Set the most restrictive lint level. More restrictive
124+
lints are capped at this level. By default, it is at
125+
`forbid` level.
126+
--index-page PATH
127+
Markdown file to be used as index page
128+
--enable-index-page
129+
To enable generation of the index page
130+
--static-root-path PATH
131+
Path string to force loading static files from in
132+
output pages. If not set, uses combinations of '../'
133+
to reach the documentation root.
134+
--disable-per-crate-search
135+
disables generating the crate selector on the search
136+
box
137+
--persist-doctests PATH
138+
Directory to persist doctest executables into
139+
--show-coverage
140+
calculate percentage of public items with
141+
documentation
142+
--enable-per-target-ignores
143+
parse ignore-foo for ignoring doctests on a per-target
144+
basis
145+
--runtool The tool to run tests with when building for a different target than host
146+
147+
--runtool-arg One (of possibly many) arguments to pass to the runtool
148+
149+
--test-builder PATH
150+
The rustc-like binary to use as the test builder
151+
--check Run rustdoc checks
152+
--generate-redirect-map
153+
Generate JSON file at the top level instead of
154+
generating HTML redirection files
155+
--emit [unversioned-shared-resources,toolchain-shared-resources,invocation-specific]
156+
Comma separated list of types of output for rustdoc to
157+
emit
158+
--no-run Compile doctests without running them
159+
--show-type-layout
160+
Include the memory layout of types in the docs
161+
--nocapture Don't capture stdout and stderr of tests
162+
--generate-link-to-definition
163+
Make the identifiers in the HTML source code pages
164+
navigable
165+
--scrape-examples-output-path collect function call information and output at the given path
166+
167+
--scrape-examples-target-crate collect function call information for functions from the target crate
168+
169+
--scrape-tests Include test code when scraping examples
170+
--with-examples path to function call information (for displaying examples in the documentation)
171+
172+
--plugin-path DIR
173+
removed, see issue #44136
174+
<https://github.com/rust-lang/rust/issues/44136> for
175+
more information
176+
--passes PASSES removed, see issue #44136
177+
<https://github.com/rust-lang/rust/issues/44136> for
178+
more information
179+
--plugins PLUGINS
180+
removed, see issue #44136
181+
<https://github.com/rust-lang/rust/issues/44136> for
182+
more information
183+
--no-defaults removed, see issue #44136
184+
<https://github.com/rust-lang/rust/issues/44136> for
185+
more information
186+
-r, --input-format [rust]
187+
removed, see issue #44136
188+
<https://github.com/rust-lang/rust/issues/44136> for
189+
more information
190+
191+
@path Read newline separated options from `path`
192+
193+
More information available at https://doc.rust-lang.org/$CHANNEL/rustdoc/what-is-rustdoc.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// nothing to see here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-include ../../run-make-fulldeps/tools.mk
2+
3+
all:
4+
$(RUSTDOC) -W help 2>&1 | diff - output-default.stdout
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a test to verify that `rustdoc` behaves the same as rustc and prints out help output for its options like -W (#88756).

0 commit comments

Comments
 (0)