rustdoc: Fix ICE report

This commit is contained in:
Eric Huss 2021-12-26 20:32:17 -08:00
parent e98309298d
commit 4413141ea9

View File

@ -64,7 +64,7 @@ pub const EXIT_FAILURE: i32 = 1;
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust/issues/new\ const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust/issues/new\
?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md"; ?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md";
const ICE_REPORT_COMPILER_FLAGS: &[&str] = &["Z", "C", "crate-type"]; const ICE_REPORT_COMPILER_FLAGS: &[&str] = &["-Z", "-C", "--crate-type"];
const ICE_REPORT_COMPILER_FLAGS_EXCLUDE: &[&str] = &["metadata", "extra-filename"]; const ICE_REPORT_COMPILER_FLAGS_EXCLUDE: &[&str] = &["metadata", "extra-filename"];
@ -1108,31 +1108,31 @@ fn parse_crate_attrs<'a>(sess: &'a Session, input: &Input) -> PResult<'a, Vec<as
/// debugging, since some ICEs only happens with non-default compiler flags /// debugging, since some ICEs only happens with non-default compiler flags
/// (and the users don't always report them). /// (and the users don't always report them).
fn extra_compiler_flags() -> Option<(Vec<String>, bool)> { fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
let args = env::args_os().map(|arg| arg.to_string_lossy().to_string()).collect::<Vec<_>>(); let mut args = env::args_os().map(|arg| arg.to_string_lossy().to_string()).peekable();
// Avoid printing help because of empty args. This can suggest the compiler
// itself is not the program root (consider RLS).
if args.len() < 2 {
return None;
}
let matches = handle_options(&args)?;
let mut result = Vec::new(); let mut result = Vec::new();
let mut excluded_cargo_defaults = false; let mut excluded_cargo_defaults = false;
for flag in ICE_REPORT_COMPILER_FLAGS { while let Some(arg) = args.next() {
let prefix = if flag.len() == 1 { "-" } else { "--" }; if let Some(a) = ICE_REPORT_COMPILER_FLAGS.iter().find(|a| arg.starts_with(*a)) {
let content = if arg.len() == a.len() {
for content in &matches.opt_strs(flag) { match args.next() {
// Split always returns the first element Some(arg) => arg.to_string(),
let name = if let Some(first) = content.split('=').next() { first } else { &content }; None => continue,
}
let content = } else if arg.get(a.len()..a.len() + 1) == Some("=") {
if ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.contains(&name) { name } else { content }; arg[a.len() + 1..].to_string()
if !ICE_REPORT_COMPILER_FLAGS_EXCLUDE.contains(&name) {
result.push(format!("{}{} {}", prefix, flag, content));
} else { } else {
arg[a.len()..].to_string()
};
if ICE_REPORT_COMPILER_FLAGS_EXCLUDE.iter().any(|exc| content.starts_with(exc)) {
excluded_cargo_defaults = true; excluded_cargo_defaults = true;
} else {
result.push(a.to_string());
match ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.iter().find(|s| content.starts_with(*s))
{
Some(s) => result.push(s.to_string()),
None => result.push(content),
}
} }
} }
} }