Fix rustdoc argument error

This commit is contained in:
Shivani Bhardwaj 2021-09-11 00:05:16 +05:30 committed by Guillaume Gomez
parent 7036449c77
commit e1b6f16fd4
3 changed files with 22 additions and 4 deletions

View File

@ -932,7 +932,7 @@ fn describe_codegen_flags() {
print_flag_list("-C", config::CG_OPTIONS); print_flag_list("-C", config::CG_OPTIONS);
} }
fn print_flag_list<T>( pub fn print_flag_list<T>(
cmdline_opt: &str, cmdline_opt: &str,
flag_list: &[(&'static str, T, &'static str, &'static str)], flag_list: &[(&'static str, T, &'static str, &'static str)],
) { ) {

View File

@ -6,6 +6,7 @@ use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_driver::print_flag_list;
use rustc_session::config::{ use rustc_session::config::{
self, parse_crate_types_from_list, parse_externs, parse_target_triple, CrateType, self, parse_crate_types_from_list, parse_externs, parse_target_triple, CrateType,
}; };
@ -310,11 +311,12 @@ impl RenderOptions {
impl Options { impl Options {
/// Parses the given command-line for options. If an error message or other early-return has /// Parses the given command-line for options. If an error message or other early-return has
/// been printed, returns `Err` with the exit code. /// 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. // Check for unstable options.
nightly_options::check_nightly_options(matches, &opts()); 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"); crate::usage("rustdoc");
return Err(0); return Err(0);
} else if matches.opt_present("version") { } else if matches.opt_present("version") {
@ -335,6 +337,21 @@ impl Options {
// check for deprecated options // check for deprecated options
check_deprecated_options(matches, &diag); 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"] { if matches.opt_strs("passes") == ["list"] {
println!("Available passes for running rustdoc:"); println!("Available passes for running rustdoc:");
for pass in passes::PASSES { for pass in passes::PASSES {
@ -415,6 +432,7 @@ impl Options {
} }
return Err(0); return Err(0);
} }
let (_lint_opts, _describe_lints, _lint_cap) = get_cmd_lint_options(matches, error_format);
if matches.free.is_empty() { if matches.free.is_empty() {
diag.struct_err("missing file operand").emit(); diag.struct_err("missing file operand").emit();

View File

@ -686,7 +686,7 @@ fn main_args(at_args: &[String]) -> MainResult {
// Note that we discard any distinction between different non-zero exit // Note that we discard any distinction between different non-zero exit
// codes from `from_matches` here. // 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, Ok(opts) => opts,
Err(code) => { Err(code) => {
return if code == 0 { return if code == 0 {