@@ -90,6 +90,8 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
90
90
#[ inline( never) ]
91
91
#[ lang = "panic_no_unwind" ] // needed by codegen for panic in nounwind function
92
92
fn panic_no_unwind ( ) -> ! {
93
+ // Could this be written in terms of:
94
+ // `panic_abort(Some(&format_args!("panic in a function that cannot unwind")))`?
93
95
if cfg ! ( feature = "panic_immediate_abort" ) {
94
96
super :: intrinsics:: abort ( )
95
97
}
@@ -109,6 +111,28 @@ fn panic_no_unwind() -> ! {
109
111
unsafe { panic_impl ( & pi) }
110
112
}
111
113
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
+
112
136
/// The entry point for panicking with a formatted message.
113
137
///
114
138
/// This is designed to reduce the amount of code required at the call
0 commit comments