Skip to content

Commit 75ba0d7

Browse files
authored
Rollup merge of rust-lang#88831 - inashivb:issue-88756, r=GuillaumeGomez,notriddle
Fix `rustdoc` argument error This is the fix is corresponding to rust-lang#88756 mentored by ```@jyn514```
2 parents 76f7332 + e53e790 commit 75ba0d7

File tree

12 files changed

+595
-28
lines changed

12 files changed

+595
-28
lines changed

compiler/rustc_driver/src/lib.rs

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

933-
fn print_flag_list<T>(
933+
pub fn print_flag_list<T>(
934934
cmdline_opt: &str,
935935
flag_list: &[(&'static str, T, &'static str, &'static str)],
936936
) {

src/librustdoc/config.rs

+20-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
};
@@ -308,11 +309,12 @@ impl RenderOptions {
308309
impl Options {
309310
/// Parses the given command-line for options. If an error message or other early-return has
310311
/// been printed, returns `Err` with the exit code.
311-
crate fn from_matches(matches: &getopts::Matches) -> Result<Options, i32> {
312+
crate fn from_matches(matches: &getopts::Matches, args: Vec<String>) -> Result<Options, i32> {
313+
let args = &args[1..];
312314
// Check for unstable options.
313315
nightly_options::check_nightly_options(matches, &opts());
314316

315-
if matches.opt_present("h") || matches.opt_present("help") {
317+
if args.is_empty() || matches.opt_present("h") || matches.opt_present("help") {
316318
crate::usage("rustdoc");
317319
return Err(0);
318320
} else if matches.opt_present("version") {
@@ -333,6 +335,21 @@ impl Options {
333335
// check for deprecated options
334336
check_deprecated_options(matches, &diag);
335337

338+
let z_flags = matches.opt_strs("Z");
339+
if z_flags.iter().any(|x| *x == "help") {
340+
print_flag_list("-Z", config::DB_OPTIONS);
341+
return Err(0);
342+
}
343+
let c_flags = matches.opt_strs("C");
344+
if c_flags.iter().any(|x| *x == "help") {
345+
print_flag_list("-C", config::CG_OPTIONS);
346+
return Err(0);
347+
}
348+
let w_flags = matches.opt_strs("W");
349+
if w_flags.iter().any(|x| *x == "help") {
350+
print_flag_list("-W", config::DB_OPTIONS);
351+
return Err(0);
352+
}
336353
if matches.opt_strs("passes") == ["list"] {
337354
println!("Available passes for running rustdoc:");
338355
for pass in passes::PASSES {
@@ -413,6 +430,7 @@ impl Options {
413430
}
414431
return Err(0);
415432
}
433+
let (_lint_opts, _describe_lints, _lint_cap) = get_cmd_lint_options(matches, error_format);
416434

417435
if matches.free.is_empty() {
418436
diag.struct_err("missing file operand").emit();

src/librustdoc/lib.rs

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

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