Skip to content

Commit 24a256c

Browse files
committed
Fix rustdoc argument error
1 parent 45e2c28 commit 24a256c

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

compiler/rustc_driver/src/lib.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 20 additions & 2 deletions
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
};
@@ -305,11 +306,12 @@ impl RenderOptions {
305306
impl Options {
306307
/// Parses the given command-line for options. If an error message or other early-return has
307308
/// been printed, returns `Err` with the exit code.
308-
crate fn from_matches(matches: &getopts::Matches) -> Result<Options, i32> {
309+
crate fn from_matches(matches: &getopts::Matches, args: Vec<String>) -> Result<Options, i32> {
310+
let args = &args[1..];
309311
// Check for unstable options.
310312
nightly_options::check_nightly_options(matches, &opts());
311313

312-
if matches.opt_present("h") || matches.opt_present("help") {
314+
if args.is_empty() || matches.opt_present("h") || matches.opt_present("help") {
313315
crate::usage("rustdoc");
314316
return Err(0);
315317
} else if matches.opt_present("version") {
@@ -330,6 +332,21 @@ impl Options {
330332
// check for deprecated options
331333
check_deprecated_options(matches, &diag);
332334

335+
let z_flags = matches.opt_strs("Z");
336+
if z_flags.iter().any(|x| *x == "help") {
337+
print_flag_list("-Z", config::DB_OPTIONS);
338+
return Err(0);
339+
}
340+
let c_flags = matches.opt_strs("C");
341+
if c_flags.iter().any(|x| *x == "help") {
342+
print_flag_list("-C", config::CG_OPTIONS);
343+
return Err(0);
344+
}
345+
let w_flags = matches.opt_strs("W");
346+
if w_flags.iter().any(|x| *x == "help") {
347+
print_flag_list("-W", config::DB_OPTIONS);
348+
return Err(0);
349+
}
333350
if matches.opt_strs("passes") == ["list"] {
334351
println!("Available passes for running rustdoc:");
335352
for pass in passes::PASSES {
@@ -410,6 +427,7 @@ impl Options {
410427
}
411428
return Err(0);
412429
}
430+
let (_lint_opts, _describe_lints, _lint_cap) = get_cmd_lint_options(matches, error_format);
413431

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

src/librustdoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ fn main_args(at_args: &[String]) -> MainResult {
687687

688688
// Note that we discard any distinction between different non-zero exit
689689
// codes from `from_matches` here.
690-
let options = match config::Options::from_matches(&matches) {
690+
let options = match config::Options::from_matches(&matches, args) {
691691
Ok(opts) => opts,
692692
Err(code) => return if code == 0 { Ok(()) } else { Err(ErrorReported) },
693693
};

0 commit comments

Comments
 (0)