@@ -90,6 +90,8 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
9090#[ inline( never) ]
9191#[ lang = "panic_no_unwind" ] // needed by codegen for panic in nounwind function
9292fn panic_no_unwind ( ) -> ! {
93+ // Could this be written in terms of:
94+ // `panic_abort(Some(&format_args!("panic in a function that cannot unwind")))`?
9395 if cfg ! ( feature = "panic_immediate_abort" ) {
9496 super :: intrinsics:: abort ( )
9597 }
@@ -109,6 +111,28 @@ fn panic_no_unwind() -> ! {
109111 unsafe { panic_impl ( & pi) }
110112}
111113
114+ /// Aborts the process, but with a properly displayed panic message.
115+ #[ cold]
116+ #[ rustc_allocator_nounwind]
117+ pub ( crate ) fn panic_abort < ' a > ( message : Option < & ' a fmt:: Arguments < ' a > > ) -> ! {
118+ if cfg ! ( feature = "panic_immediate_abort" ) {
119+ super :: intrinsics:: abort ( )
120+ }
121+
122+ // NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
123+ // that gets resolved to the `#[panic_handler]` function.
124+ extern "Rust" {
125+ #[ lang = "panic_impl" ]
126+ fn panic_impl ( pi : & PanicInfo < ' _ > ) -> !;
127+ }
128+
129+ // PanicInfo with the `can_unwind` flag set to false forces an abort.
130+ let pi = PanicInfo :: internal_constructor ( message, Location :: caller ( ) , false ) ;
131+
132+ // SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call.
133+ unsafe { panic_impl ( & pi) }
134+ }
135+
112136/// The entry point for panicking with a formatted message.
113137///
114138/// This is designed to reduce the amount of code required at the call
0 commit comments