mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
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.
This commit is contained in:
parent
5ca6e98f13
commit
bad2af1d38
@ -37,7 +37,7 @@ use rustc_metadata::locator;
|
||||
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
|
||||
use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, TrimmedDefPaths};
|
||||
use rustc_session::cstore::MetadataLoader;
|
||||
use rustc_session::getopts;
|
||||
use rustc_session::getopts::{self, Matches};
|
||||
use rustc_session::lint::{Lint, LintId};
|
||||
use rustc_session::{config, Session};
|
||||
use rustc_session::{early_error, early_error_no_abort, early_warn};
|
||||
@ -956,6 +956,46 @@ Available lint options:
|
||||
}
|
||||
}
|
||||
|
||||
/// Show help for flag categories shared between rustdoc and rustc.
|
||||
///
|
||||
/// Returns whether a help option was printed.
|
||||
pub fn describe_flag_categories(matches: &Matches) -> bool {
|
||||
// Handle the special case of -Wall.
|
||||
let wall = matches.opt_strs("W");
|
||||
if wall.iter().any(|x| *x == "all") {
|
||||
print_wall_help();
|
||||
rustc_errors::FatalError.raise();
|
||||
}
|
||||
|
||||
// Don't handle -W help here, because we might first load plugins.
|
||||
let debug_flags = matches.opt_strs("Z");
|
||||
if debug_flags.iter().any(|x| *x == "help") {
|
||||
describe_debug_flags();
|
||||
return true;
|
||||
}
|
||||
|
||||
let cg_flags = matches.opt_strs("C");
|
||||
if cg_flags.iter().any(|x| *x == "help") {
|
||||
describe_codegen_flags();
|
||||
return true;
|
||||
}
|
||||
|
||||
if cg_flags.iter().any(|x| *x == "no-stack-check") {
|
||||
early_warn(
|
||||
ErrorOutputType::default(),
|
||||
"the --no-stack-check flag is deprecated and does nothing",
|
||||
);
|
||||
}
|
||||
|
||||
if cg_flags.iter().any(|x| *x == "passes=list") {
|
||||
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
|
||||
get_codegen_backend(&None, backend_name).print_passes();
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
fn describe_debug_flags() {
|
||||
println!("\nAvailable options:\n");
|
||||
print_flag_list("-Z", config::Z_OPTIONS);
|
||||
@ -966,7 +1006,7 @@ fn describe_codegen_flags() {
|
||||
print_flag_list("-C", config::CG_OPTIONS);
|
||||
}
|
||||
|
||||
pub fn print_flag_list<T>(
|
||||
fn print_flag_list<T>(
|
||||
cmdline_opt: &str,
|
||||
flag_list: &[(&'static str, T, &'static str, &'static str)],
|
||||
) {
|
||||
@ -1059,37 +1099,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Handle the special case of -Wall.
|
||||
let wall = matches.opt_strs("W");
|
||||
if wall.iter().any(|x| *x == "all") {
|
||||
print_wall_help();
|
||||
rustc_errors::FatalError.raise();
|
||||
}
|
||||
|
||||
// Don't handle -W help here, because we might first load plugins.
|
||||
let debug_flags = matches.opt_strs("Z");
|
||||
if debug_flags.iter().any(|x| *x == "help") {
|
||||
describe_debug_flags();
|
||||
return None;
|
||||
}
|
||||
|
||||
let cg_flags = matches.opt_strs("C");
|
||||
|
||||
if cg_flags.iter().any(|x| *x == "help") {
|
||||
describe_codegen_flags();
|
||||
return None;
|
||||
}
|
||||
|
||||
if cg_flags.iter().any(|x| *x == "no-stack-check") {
|
||||
early_warn(
|
||||
ErrorOutputType::default(),
|
||||
"the --no-stack-check flag is deprecated and does nothing",
|
||||
);
|
||||
}
|
||||
|
||||
if cg_flags.iter().any(|x| *x == "passes=list") {
|
||||
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
|
||||
get_codegen_backend(&None, backend_name).print_passes();
|
||||
if describe_flag_categories(&matches) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ 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,
|
||||
};
|
||||
@ -328,14 +327,7 @@ impl Options {
|
||||
return Err(0);
|
||||
}
|
||||
|
||||
let z_flags = matches.opt_strs("Z");
|
||||
if z_flags.iter().any(|x| *x == "help") {
|
||||
print_flag_list("-Z", config::Z_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);
|
||||
if rustc_driver::describe_flag_categories(&matches) {
|
||||
return Err(0);
|
||||
}
|
||||
|
||||
|
@ -398,6 +398,8 @@ fn run_test(
|
||||
compiler.stdin(Stdio::piped());
|
||||
compiler.stderr(Stdio::piped());
|
||||
|
||||
debug!("compiler invocation for doctest: {:?}", compiler);
|
||||
|
||||
let mut child = compiler.spawn().expect("Failed to spawn rustc process");
|
||||
{
|
||||
let stdin = child.stdin.as_mut().expect("Failed to open stdin");
|
||||
|
Loading…
Reference in New Issue
Block a user