about summary refs log tree commit diff
path: root/src/librustdoc
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-06-27 22:35:06 +0200
committerGitHub <noreply@github.com>2022-06-27 22:35:06 +0200
commit38bfa9c4f83b92c7ece0ff3a78e1ba16e7a9cf80 (patch)
tree7acd4ed5aee1df251e60fbfb5e2a8ba52f2dc9b0 /src/librustdoc
parent8e52fa87ebbe3ea2ad38b429292e4a22300188d7 (diff)
parent768129d4bdca2354cecb5c0ab91ae555864d49d0 (diff)
Rollup merge of #98331 - GuillaumeGomez:rustdoc-arg-error, r=notriddle
Fix rustdoc argument error

Fixes #88756.

It's a take over of #88831. I cherry-picked the commits, fixed the merge conflict and the failing test.

cc `@inashivb` `@jyn514`

r? `@notriddle`
Diffstat (limited to 'src/librustdoc')
-rw-r--r--src/librustdoc/config.rs24
-rw-r--r--src/librustdoc/lib.rs2
2 files changed, 23 insertions, 3 deletions
diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs
index e59324331ae..6e3651665c8 100644
--- a/src/librustdoc/config.rs
+++ b/src/librustdoc/config.rs
@@ -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,
 };
@@ -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") {
@@ -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 {
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index 54b85166041..db4c3d10237 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -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 {