|
7 | 7 | #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] |
8 | 8 | #![feature(lazy_cell)] |
9 | 9 | #![feature(decl_macro)] |
10 | | -#![feature(ice_to_disk)] |
| 10 | +#![feature(panic_update_hook)] |
11 | 11 | #![feature(let_chains)] |
12 | 12 | #![recursion_limit = "256"] |
13 | 13 | #![allow(rustc::potential_query_instability)] |
@@ -50,9 +50,9 @@ use std::collections::BTreeMap; |
50 | 50 | use std::env; |
51 | 51 | use std::ffi::OsString; |
52 | 52 | use std::fmt::Write as _; |
53 | | -use std::fs; |
| 53 | +use std::fs::{self, File}; |
54 | 54 | use std::io::{self, IsTerminal, Read, Write}; |
55 | | -use std::panic::{self, catch_unwind}; |
| 55 | +use std::panic::{self, catch_unwind, PanicInfo}; |
56 | 56 | use std::path::PathBuf; |
57 | 57 | use std::process::{self, Command, Stdio}; |
58 | 58 | use std::str; |
@@ -1323,31 +1323,42 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler)) |
1323 | 1323 | std::env::set_var("RUST_BACKTRACE", "full"); |
1324 | 1324 | } |
1325 | 1325 |
|
1326 | | - panic::set_hook(Box::new(move |info| { |
1327 | | - // If the error was caused by a broken pipe then this is not a bug. |
1328 | | - // Write the error and return immediately. See #98700. |
1329 | | - #[cfg(windows)] |
1330 | | - if let Some(msg) = info.payload().downcast_ref::<String>() { |
1331 | | - if msg.starts_with("failed printing to stdout: ") && msg.ends_with("(os error 232)") { |
1332 | | - // the error code is already going to be reported when the panic unwinds up the stack |
1333 | | - let handler = EarlyErrorHandler::new(ErrorOutputType::default()); |
1334 | | - let _ = handler.early_error_no_abort(msg.clone()); |
1335 | | - return; |
1336 | | - } |
1337 | | - }; |
1338 | | - |
1339 | | - // Invoke the default handler, which prints the actual panic message and optionally a backtrace |
1340 | | - // Don't do this for delayed bugs, which already emit their own more useful backtrace. |
1341 | | - if !info.payload().is::<rustc_errors::DelayedBugPanic>() { |
1342 | | - std::panic_hook_with_disk_dump(info, ice_path().as_deref()); |
| 1326 | + panic::update_hook(Box::new( |
| 1327 | + move |default_hook: &(dyn Fn(&PanicInfo<'_>) + Send + Sync + 'static), |
| 1328 | + info: &PanicInfo<'_>| { |
| 1329 | + // If the error was caused by a broken pipe then this is not a bug. |
| 1330 | + // Write the error and return immediately. See #98700. |
| 1331 | + #[cfg(windows)] |
| 1332 | + if let Some(msg) = info.payload().downcast_ref::<String>() { |
| 1333 | + if msg.starts_with("failed printing to stdout: ") && msg.ends_with("(os error 232)") |
| 1334 | + { |
| 1335 | + // the error code is already going to be reported when the panic unwinds up the stack |
| 1336 | + let handler = EarlyErrorHandler::new(ErrorOutputType::default()); |
| 1337 | + let _ = handler.early_error_no_abort(msg.clone()); |
| 1338 | + return; |
| 1339 | + } |
| 1340 | + }; |
1343 | 1341 |
|
1344 | | - // Separate the output with an empty line |
1345 | | - eprintln!(); |
1346 | | - } |
| 1342 | + // Invoke the default handler, which prints the actual panic message and optionally a backtrace |
| 1343 | + // Don't do this for delayed bugs, which already emit their own more useful backtrace. |
| 1344 | + if !info.payload().is::<rustc_errors::DelayedBugPanic>() { |
| 1345 | + default_hook(info); |
| 1346 | + // Separate the output with an empty line |
| 1347 | + eprintln!(); |
| 1348 | + |
| 1349 | + if let Some(ice_path) = ice_path() |
| 1350 | + && let Ok(mut out) = |
| 1351 | + File::options().create(true).append(true).open(&ice_path) |
| 1352 | + { |
| 1353 | + let _ = |
| 1354 | + write!(&mut out, "{info}{:#}", std::backtrace::Backtrace::force_capture()); |
| 1355 | + } |
| 1356 | + } |
1347 | 1357 |
|
1348 | | - // Print the ICE message |
1349 | | - report_ice(info, bug_report_url, extra_info); |
1350 | | - })); |
| 1358 | + // Print the ICE message |
| 1359 | + report_ice(info, bug_report_url, extra_info); |
| 1360 | + }, |
| 1361 | + )); |
1351 | 1362 | } |
1352 | 1363 |
|
1353 | 1364 | /// Prints the ICE message, including query stack, but without backtrace. |
|
0 commit comments