Skip to content

Commit 9298bd8

Browse files
authored
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
rustdoc: Fix ICE report The ICE report in rustdoc was confusing because it was returning an argument parse error: ``` thread 'rustc' panicked at 'aborting due to `-Z treat-err-as-bug=1`', compiler/rustc_errors/src/lib.rs:1212:27 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace error: internal compiler error: unexpected panic error: Unrecognized option: 'crate-version' ``` This is because the ICE reporter was trying to parse the arguments as rustc, not rustdoc. Since an argument error is a fatal error, it was early-exiting with the argument error due to unwinding. This changes it to be a more primitive scan of the arguments. The arguments being checked are pretty simple, and only have a small handful of forms that are easy to check for. It now looks like this: ``` thread 'rustc' panicked at 'aborting due to `-Z treat-err-as-bug=1`', compiler/rustc_errors/src/lib.rs:1212:27 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace error: internal compiler error: unexpected panic note: the compiler unexpectedly panicked. this is a bug. note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md note: rustc 1.59.0-dev running on x86_64-apple-darwin note: compiler flags: --crate-type lib -Z treat-err-as-bug note: some of the compiler flags provided by cargo are hidden query stack during panic: end of query stack ``` It still says `rustc`, but I can live with that.
2 parents 796bf14 + 4413141 commit 9298bd8

File tree

1 file changed

+21
-21
lines changed
  • compiler/rustc_driver/src

1 file changed

+21
-21
lines changed

compiler/rustc_driver/src/lib.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub const EXIT_FAILURE: i32 = 1;
6666
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust/issues/new\
6767
?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md";
6868

69-
const ICE_REPORT_COMPILER_FLAGS: &[&str] = &["Z", "C", "crate-type"];
69+
const ICE_REPORT_COMPILER_FLAGS: &[&str] = &["-Z", "-C", "--crate-type"];
7070

7171
const ICE_REPORT_COMPILER_FLAGS_EXCLUDE: &[&str] = &["metadata", "extra-filename"];
7272

@@ -1100,31 +1100,31 @@ fn parse_crate_attrs<'a>(sess: &'a Session, input: &Input) -> PResult<'a, Vec<as
11001100
/// debugging, since some ICEs only happens with non-default compiler flags
11011101
/// (and the users don't always report them).
11021102
fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
1103-
let args = env::args_os().map(|arg| arg.to_string_lossy().to_string()).collect::<Vec<_>>();
1103+
let mut args = env::args_os().map(|arg| arg.to_string_lossy().to_string()).peekable();
11041104

1105-
// Avoid printing help because of empty args. This can suggest the compiler
1106-
// itself is not the program root (consider RLS).
1107-
if args.len() < 2 {
1108-
return None;
1109-
}
1110-
1111-
let matches = handle_options(&args)?;
11121105
let mut result = Vec::new();
11131106
let mut excluded_cargo_defaults = false;
1114-
for flag in ICE_REPORT_COMPILER_FLAGS {
1115-
let prefix = if flag.len() == 1 { "-" } else { "--" };
1116-
1117-
for content in &matches.opt_strs(flag) {
1118-
// Split always returns the first element
1119-
let name = if let Some(first) = content.split('=').next() { first } else { &content };
1120-
1121-
let content =
1122-
if ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.contains(&name) { name } else { content };
1123-
1124-
if !ICE_REPORT_COMPILER_FLAGS_EXCLUDE.contains(&name) {
1125-
result.push(format!("{}{} {}", prefix, flag, content));
1107+
while let Some(arg) = args.next() {
1108+
if let Some(a) = ICE_REPORT_COMPILER_FLAGS.iter().find(|a| arg.starts_with(*a)) {
1109+
let content = if arg.len() == a.len() {
1110+
match args.next() {
1111+
Some(arg) => arg.to_string(),
1112+
None => continue,
1113+
}
1114+
} else if arg.get(a.len()..a.len() + 1) == Some("=") {
1115+
arg[a.len() + 1..].to_string()
11261116
} else {
1117+
arg[a.len()..].to_string()
1118+
};
1119+
if ICE_REPORT_COMPILER_FLAGS_EXCLUDE.iter().any(|exc| content.starts_with(exc)) {
11271120
excluded_cargo_defaults = true;
1121+
} else {
1122+
result.push(a.to_string());
1123+
match ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.iter().find(|s| content.starts_with(*s))
1124+
{
1125+
Some(s) => result.push(s.to_string()),
1126+
None => result.push(content),
1127+
}
11281128
}
11291129
}
11301130
}

0 commit comments

Comments
 (0)