diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2022-02-03 22:20:23 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-03 22:20:23 +0900 |
| commit | 9298bd8197ebffac1d310ff90f5845a30a512a23 (patch) | |
| tree | 4a44ec6f0fccf4154d2861471a4ef577d87ea52f | |
| parent | 796bf14f2e129283d9daee7f05d14c2dfa76d643 (diff) | |
| parent | 4413141ea96cfe4edbe417f352b13160556bd48e (diff) | |
| download | rust-9298bd8197ebffac1d310ff90f5845a30a512a23.tar.gz rust-9298bd8197ebffac1d310ff90f5845a30a512a23.zip | |
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.
| -rw-r--r-- | compiler/rustc_driver/src/lib.rs | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 0f490c33102..a91285a390a 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -66,7 +66,7 @@ pub const EXIT_FAILURE: i32 = 1; 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"; -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"]; @@ -1100,31 +1100,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 /// (and the users don't always report them). 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 excluded_cargo_defaults = false; - for flag in ICE_REPORT_COMPILER_FLAGS { - let prefix = if flag.len() == 1 { "-" } else { "--" }; - - for content in &matches.opt_strs(flag) { - // Split always returns the first element - let name = if let Some(first) = content.split('=').next() { first } else { &content }; - - let content = - if ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.contains(&name) { name } else { content }; - - if !ICE_REPORT_COMPILER_FLAGS_EXCLUDE.contains(&name) { - result.push(format!("{}{} {}", prefix, flag, content)); + while let Some(arg) = args.next() { + if let Some(a) = ICE_REPORT_COMPILER_FLAGS.iter().find(|a| arg.starts_with(*a)) { + let content = if arg.len() == a.len() { + match args.next() { + Some(arg) => arg.to_string(), + None => continue, + } + } else if arg.get(a.len()..a.len() + 1) == Some("=") { + arg[a.len() + 1..].to_string() } else { + arg[a.len()..].to_string() + }; + if ICE_REPORT_COMPILER_FLAGS_EXCLUDE.iter().any(|exc| content.starts_with(exc)) { 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), + } } } } |
