Skip to content

Commit bad2af1

Browse files
committed
Make rustdoc and rustc's help match exactly
Before, rustdoc was missing `-C passes=list` and the "Available options" header. Making these match allows testing that they match exactly.
1 parent 5ca6e98 commit bad2af1

File tree

3 files changed

+46
-42
lines changed

3 files changed

+46
-42
lines changed

compiler/rustc_driver_impl/src/lib.rs

+43-33
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use rustc_metadata::locator;
3737
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
3838
use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, TrimmedDefPaths};
3939
use rustc_session::cstore::MetadataLoader;
40-
use rustc_session::getopts;
40+
use rustc_session::getopts::{self, Matches};
4141
use rustc_session::lint::{Lint, LintId};
4242
use rustc_session::{config, Session};
4343
use rustc_session::{early_error, early_error_no_abort, early_warn};
@@ -956,6 +956,46 @@ Available lint options:
956956
}
957957
}
958958

959+
/// Show help for flag categories shared between rustdoc and rustc.
960+
///
961+
/// Returns whether a help option was printed.
962+
pub fn describe_flag_categories(matches: &Matches) -> bool {
963+
// Handle the special case of -Wall.
964+
let wall = matches.opt_strs("W");
965+
if wall.iter().any(|x| *x == "all") {
966+
print_wall_help();
967+
rustc_errors::FatalError.raise();
968+
}
969+
970+
// Don't handle -W help here, because we might first load plugins.
971+
let debug_flags = matches.opt_strs("Z");
972+
if debug_flags.iter().any(|x| *x == "help") {
973+
describe_debug_flags();
974+
return true;
975+
}
976+
977+
let cg_flags = matches.opt_strs("C");
978+
if cg_flags.iter().any(|x| *x == "help") {
979+
describe_codegen_flags();
980+
return true;
981+
}
982+
983+
if cg_flags.iter().any(|x| *x == "no-stack-check") {
984+
early_warn(
985+
ErrorOutputType::default(),
986+
"the --no-stack-check flag is deprecated and does nothing",
987+
);
988+
}
989+
990+
if cg_flags.iter().any(|x| *x == "passes=list") {
991+
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
992+
get_codegen_backend(&None, backend_name).print_passes();
993+
return true;
994+
}
995+
996+
false
997+
}
998+
959999
fn describe_debug_flags() {
9601000
println!("\nAvailable options:\n");
9611001
print_flag_list("-Z", config::Z_OPTIONS);
@@ -966,7 +1006,7 @@ fn describe_codegen_flags() {
9661006
print_flag_list("-C", config::CG_OPTIONS);
9671007
}
9681008

969-
pub fn print_flag_list<T>(
1009+
fn print_flag_list<T>(
9701010
cmdline_opt: &str,
9711011
flag_list: &[(&'static str, T, &'static str, &'static str)],
9721012
) {
@@ -1059,37 +1099,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
10591099
return None;
10601100
}
10611101

1062-
// Handle the special case of -Wall.
1063-
let wall = matches.opt_strs("W");
1064-
if wall.iter().any(|x| *x == "all") {
1065-
print_wall_help();
1066-
rustc_errors::FatalError.raise();
1067-
}
1068-
1069-
// Don't handle -W help here, because we might first load plugins.
1070-
let debug_flags = matches.opt_strs("Z");
1071-
if debug_flags.iter().any(|x| *x == "help") {
1072-
describe_debug_flags();
1073-
return None;
1074-
}
1075-
1076-
let cg_flags = matches.opt_strs("C");
1077-
1078-
if cg_flags.iter().any(|x| *x == "help") {
1079-
describe_codegen_flags();
1080-
return None;
1081-
}
1082-
1083-
if cg_flags.iter().any(|x| *x == "no-stack-check") {
1084-
early_warn(
1085-
ErrorOutputType::default(),
1086-
"the --no-stack-check flag is deprecated and does nothing",
1087-
);
1088-
}
1089-
1090-
if cg_flags.iter().any(|x| *x == "passes=list") {
1091-
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
1092-
get_codegen_backend(&None, backend_name).print_passes();
1102+
if describe_flag_categories(&matches) {
10931103
return None;
10941104
}
10951105

src/librustdoc/config.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::path::PathBuf;
66
use std::str::FromStr;
77

88
use rustc_data_structures::fx::FxHashMap;
9-
use rustc_driver::print_flag_list;
109
use rustc_session::config::{
1110
self, parse_crate_types_from_list, parse_externs, parse_target_triple, CrateType,
1211
};
@@ -328,14 +327,7 @@ impl Options {
328327
return Err(0);
329328
}
330329

331-
let z_flags = matches.opt_strs("Z");
332-
if z_flags.iter().any(|x| *x == "help") {
333-
print_flag_list("-Z", config::Z_OPTIONS);
334-
return Err(0);
335-
}
336-
let c_flags = matches.opt_strs("C");
337-
if c_flags.iter().any(|x| *x == "help") {
338-
print_flag_list("-C", config::CG_OPTIONS);
330+
if rustc_driver::describe_flag_categories(&matches) {
339331
return Err(0);
340332
}
341333

src/librustdoc/doctest.rs

+2
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ fn run_test(
398398
compiler.stdin(Stdio::piped());
399399
compiler.stderr(Stdio::piped());
400400

401+
debug!("compiler invocation for doctest: {:?}", compiler);
402+
401403
let mut child = compiler.spawn().expect("Failed to spawn rustc process");
402404
{
403405
let stdin = child.stdin.as_mut().expect("Failed to open stdin");

0 commit comments

Comments
 (0)