@@ -1161,12 +1161,18 @@ pub fn catch_fatal_errors<F: FnOnce() -> R, R>(f: F) -> Result<R, ErrorReported>
11611161lazy_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.
12341243pub fn install_ice_hook ( ) {
12351244 lazy_static:: initialize ( & DEFAULT_HOOK ) ;
12361245}
0 commit comments