Skip to content

Commit e1b6f16

Browse files
inashivbGuillaumeGomez
authored andcommitted
Fix rustdoc argument error
1 parent 7036449 commit e1b6f16

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

compiler/rustc_driver/src/lib.rs

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

935-
fn print_flag_list<T>(
935+
pub fn print_flag_list<T>(
936936
cmdline_opt: &str,
937937
flag_list: &[(&'static str, T, &'static str, &'static str)],
938938
) {

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

317-
if matches.opt_present("h") || matches.opt_present("help") {
319+
if args.is_empty() || matches.opt_present("h") || matches.opt_present("help") {
318320
crate::usage("rustdoc");
319321
return Err(0);
320322
} else if matches.opt_present("version") {
@@ -335,6 +337,21 @@ impl Options {
335337
// check for deprecated options
336338
check_deprecated_options(matches, &diag);
337339

340+
let z_flags = matches.opt_strs("Z");
341+
if z_flags.iter().any(|x| *x == "help") {
342+
print_flag_list("-Z", config::DB_OPTIONS);
343+
return Err(0);
344+
}
345+
let c_flags = matches.opt_strs("C");
346+
if c_flags.iter().any(|x| *x == "help") {
347+
print_flag_list("-C", config::CG_OPTIONS);
348+
return Err(0);
349+
}
350+
let w_flags = matches.opt_strs("W");
351+
if w_flags.iter().any(|x| *x == "help") {
352+
print_flag_list("-W", config::DB_OPTIONS);
353+
return Err(0);
354+
}
338355
if matches.opt_strs("passes") == ["list"] {
339356
println!("Available passes for running rustdoc:");
340357
for pass in passes::PASSES {
@@ -415,6 +432,7 @@ impl Options {
415432
}
416433
return Err(0);
417434
}
435+
let (_lint_opts, _describe_lints, _lint_cap) = get_cmd_lint_options(matches, error_format);
418436

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

src/librustdoc/lib.rs

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

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

0 commit comments

Comments
 (0)