Skip to content

Commit 3e2d4d2

Browse files
Document the ICE hook and make it more flexible
1 parent 0353339 commit 3e2d4d2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/librustc_driver/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,12 +1161,18 @@ pub fn catch_fatal_errors<F: FnOnce() -> R, R>(f: F) -> Result<R, ErrorReported>
11611161
lazy_static! {
11621162
static ref DEFAULT_HOOK: Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static> = {
11631163
let hook = panic::take_hook();
1164-
panic::set_hook(Box::new(report_ice));
1164+
panic::set_hook(Box::new(|info| report_ice(info, BUG_REPORT_URL)));
11651165
hook
11661166
};
11671167
}
11681168

1169-
pub fn report_ice(info: &panic::PanicInfo<'_>) {
1169+
/// Prints the ICE message, including backtrace and query stack.
1170+
///
1171+
/// The message will point the user at `bug_report_url` to report the ICE.
1172+
///
1173+
/// When `install_ice_hook` is called, this function will be called as the panic
1174+
/// hook.
1175+
pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
11701176
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
11711177
(*DEFAULT_HOOK)(info);
11721178

@@ -1192,7 +1198,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>) {
11921198

11931199
let mut xs: Vec<Cow<'static, str>> = vec![
11941200
"the compiler unexpectedly panicked. this is a bug.".into(),
1195-
format!("we would appreciate a bug report: {}", BUG_REPORT_URL).into(),
1201+
format!("we would appreciate a bug report: {}", bug_report_url).into(),
11961202
format!("rustc {} running on {}",
11971203
option_env!("CFG_VERSION").unwrap_or("unknown_version"),
11981204
config::host_triple()).into(),
@@ -1231,6 +1237,9 @@ pub fn report_ice(info: &panic::PanicInfo<'_>) {
12311237
}
12321238
}
12331239

1240+
/// Installs a panic hook that will print the ICE message on unexpected panics.
1241+
///
1242+
/// A custom rustc driver can skip calling this to set up a custom ICE hook.
12341243
pub fn install_ice_hook() {
12351244
lazy_static::initialize(&DEFAULT_HOOK);
12361245
}

0 commit comments

Comments
 (0)