Skip to content

Commit

Permalink
Rollup merge of rust-lang#98331 - GuillaumeGomez:rustdoc-arg-error, r…
Browse files Browse the repository at this point in the history
…=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`
  • Loading branch information
matthiaskrgr authored Jun 27, 2022
2 parents 8e52fa8 + 768129d commit 38bfa9c
Show file tree
Hide file tree
Showing 12 changed files with 614 additions and 28 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ fn describe_codegen_flags() {
print_flag_list("-C", config::CG_OPTIONS);
}

fn print_flag_list<T>(
pub fn print_flag_list<T>(
cmdline_opt: &str,
flag_list: &[(&'static str, T, &'static str, &'static str)],
) {
Expand Down
24 changes: 22 additions & 2 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::path::PathBuf;
use std::str::FromStr;

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

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

let z_flags = matches.opt_strs("Z");
if z_flags.iter().any(|x| *x == "help") {
print_flag_list("-Z", config::DB_OPTIONS);
return Err(0);
}
let c_flags = matches.opt_strs("C");
if c_flags.iter().any(|x| *x == "help") {
print_flag_list("-C", config::CG_OPTIONS);
return Err(0);
}
let w_flags = matches.opt_strs("W");
if w_flags.iter().any(|x| *x == "help") {
print_flag_list("-W", config::DB_OPTIONS);
return Err(0);
}
if matches.opt_strs("passes") == ["list"] {
println!("Available passes for running rustdoc:");
for pass in passes::PASSES {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ fn main_args(at_args: &[String]) -> MainResult {

// Note that we discard any distinction between different non-zero exit
// codes from `from_matches` here.
let options = match config::Options::from_matches(&matches) {
let options = match config::Options::from_matches(&matches, args) {
Ok(opts) => opts,
Err(code) => {
return if code == 0 {
Expand Down
4 changes: 4 additions & 0 deletions src/test/run-make/issue-88756-default-output/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-include ../../run-make-fulldeps/tools.mk

all:
$(BARE_RUSTDOC) 2>&1 | sed -E 's@/nightly/|/beta/|/stable/|/1\.[0-9]+\.[0-9]+/@/$$CHANNEL/@g' | diff - output-default.stdout
1 change: 1 addition & 0 deletions src/test/run-make/issue-88756-default-output/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a test to verify that the default behavior of `rustdoc` is printing out help output instead of erroring out (#88756).
193 changes: 193 additions & 0 deletions src/test/run-make/issue-88756-default-output/output-default.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
rustdoc [options] <input>

Options:
-h, --help show this help message
-V, --version print rustdoc's version
-v, --verbose use verbose output
-w, --output-format [html]
the output type to write
--output PATH Which directory to place the output. This option is
deprecated, use --out-dir instead.
-o, --out-dir PATH which directory to place the output
--crate-name NAME
specify the name of this crate
--crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]
Comma separated list of types of crates
for the compiler to emit
-L, --library-path DIR
directory to add to crate search path
--cfg pass a --cfg to rustc
--check-cfg pass a --check-cfg to rustc
--extern NAME[=PATH]
pass an --extern to rustc
--extern-html-root-url NAME=URL
base URL to use for dependencies; for example,
"std=/doc" links std::vec::Vec to
/doc/std/vec/struct.Vec.html
--extern-html-root-takes-precedence
give precedence to `--extern-html-root-url`, not
`html_root_url`
-C, --codegen OPT[=VALUE]
pass a codegen option to rustc
--document-private-items
document private items
--document-hidden-items
document items that have doc(hidden)
--test run code examples as tests
--test-args ARGS
arguments to pass to the test runner
--test-run-directory PATH
The working directory in which to run tests
--target TRIPLE target triple to document
--markdown-css FILES
CSS files to include via <link> in a rendered Markdown
file
--html-in-header FILES
files to include inline in the <head> section of a
rendered Markdown file or generated documentation
--html-before-content FILES
files to include inline between <body> and the content
of a rendered Markdown file or generated documentation
--html-after-content FILES
files to include inline between the content and
</body> of a rendered Markdown file or generated
documentation
--markdown-before-content FILES
files to include inline between <body> and the content
of a rendered Markdown file or generated documentation
--markdown-after-content FILES
files to include inline between the content and
</body> of a rendered Markdown file or generated
documentation
--markdown-playground-url URL
URL to send code snippets to
--markdown-no-toc
don't include table of contents
-e, --extend-css PATH
To add some CSS rules with a given file to generate
doc with your own theme. However, your theme might
break if the rustdoc's generated HTML changes, so be
careful!
-Z FLAG internal and debugging options (only on nightly build)
--sysroot PATH Override the system root
--playground-url URL
URL to send code snippets to, may be reset by
--markdown-playground-url or
`#![doc(html_playground_url=...)]`
--display-doctest-warnings
show warnings that originate in doctests
--crate-version VERSION
crate version to print into documentation
--sort-modules-by-appearance
sort modules by where they appear in the program,
rather than alphabetically
--default-theme THEME
Set the default theme. THEME should be the theme name,
generally lowercase. If an unknown default theme is
specified, the builtin default is used. The set of
themes, and the rustdoc built-in default, are not
stable.
--default-setting SETTING[=VALUE]
Default value for a rustdoc setting (used when
"rustdoc-SETTING" is absent from web browser Local
Storage). If VALUE is not supplied, "true" is used.
Supported SETTINGs and VALUEs are not documented and
not stable.
--theme FILES additional themes which will be added to the generated
docs
--check-theme FILES
check if given theme is valid
--resource-suffix PATH
suffix to add to CSS and JavaScript files, e.g.,
"light.css" will become "light-suffix.css"
--edition EDITION
edition to use when compiling rust code (default:
2015)
--color auto|always|never
Configure coloring of output:
auto = colorize, if output goes to a tty (default);
always = always colorize output;
never = never colorize output
--error-format human|json|short
How errors and other messages are produced
--json CONFIG Configure the structure of JSON diagnostics
--disable-minification
Disable minification applied on JS files
-A, --allow LINT Set lint allowed
-W, --warn LINT Set lint warnings
--force-warn LINT
Set lint force-warn
-D, --deny LINT Set lint denied
-F, --forbid LINT Set lint forbidden
--cap-lints LEVEL
Set the most restrictive lint level. More restrictive
lints are capped at this level. By default, it is at
`forbid` level.
--index-page PATH
Markdown file to be used as index page
--enable-index-page
To enable generation of the index page
--static-root-path PATH
Path string to force loading static files from in
output pages. If not set, uses combinations of '../'
to reach the documentation root.
--disable-per-crate-search
disables generating the crate selector on the search
box
--persist-doctests PATH
Directory to persist doctest executables into
--show-coverage
calculate percentage of public items with
documentation
--enable-per-target-ignores
parse ignore-foo for ignoring doctests on a per-target
basis
--runtool The tool to run tests with when building for a different target than host

--runtool-arg One (of possibly many) arguments to pass to the runtool

--test-builder PATH
The rustc-like binary to use as the test builder
--check Run rustdoc checks
--generate-redirect-map
Generate JSON file at the top level instead of
generating HTML redirection files
--emit [unversioned-shared-resources,toolchain-shared-resources,invocation-specific]
Comma separated list of types of output for rustdoc to
emit
--no-run Compile doctests without running them
--show-type-layout
Include the memory layout of types in the docs
--nocapture Don't capture stdout and stderr of tests
--generate-link-to-definition
Make the identifiers in the HTML source code pages
navigable
--scrape-examples-output-path collect function call information and output at the given path

--scrape-examples-target-crate collect function call information for functions from the target crate

--scrape-tests Include test code when scraping examples
--with-examples path to function call information (for displaying examples in the documentation)

--plugin-path DIR
removed, see issue #44136
<https://github.com/rust-lang/rust/issues/44136> for
more information
--passes PASSES removed, see issue #44136
<https://github.com/rust-lang/rust/issues/44136> for
more information
--plugins PLUGINS
removed, see issue #44136
<https://github.com/rust-lang/rust/issues/44136> for
more information
--no-defaults removed, see issue #44136
<https://github.com/rust-lang/rust/issues/44136> for
more information
-r, --input-format [rust]
removed, see issue #44136
<https://github.com/rust-lang/rust/issues/44136> for
more information

@path Read newline separated options from `path`

More information available at https://doc.rust-lang.org/$CHANNEL/rustdoc/what-is-rustdoc.html
1 change: 1 addition & 0 deletions src/test/run-make/issue-88756-default-output/x.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// nothing to see here
4 changes: 4 additions & 0 deletions src/test/run-make/issue-88756-opt-help/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-include ../../run-make-fulldeps/tools.mk

all:
$(RUSTDOC) -W help 2>&1 | diff - output-default.stdout
1 change: 1 addition & 0 deletions src/test/run-make/issue-88756-opt-help/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +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).
Loading

0 comments on commit 38bfa9c

Please sign in to comment.