File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,31 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
77
77
panic ! ( "index out of bounds: the len is {} but the index is {}" , len, index)
78
78
}
79
79
80
+ #[ cfg( not( bootstrap) ) ]
81
+ #[ cold]
82
+ #[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) ) ]
83
+ #[ track_caller]
84
+ #[ lang = "panic_no_unwind" ] // needed by codegen for panic in nounwind function
85
+ fn panic_no_unwind ( ) -> ! {
86
+ if cfg ! ( feature = "panic_immediate_abort" ) {
87
+ super :: intrinsics:: abort ( )
88
+ }
89
+
90
+ // NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
91
+ // that gets resolved to the `#[panic_handler]` function.
92
+ extern "Rust" {
93
+ #[ lang = "panic_impl" ]
94
+ fn panic_impl ( pi : & PanicInfo < ' _ > ) -> !;
95
+ }
96
+
97
+ // PanicInfo with the `can_unwind` flag set to false forces an abort.
98
+ let fmt = format_args ! ( "panic in a function that cannot unwind" ) ;
99
+ let pi = PanicInfo :: internal_constructor ( Some ( & fmt) , Location :: caller ( ) , false ) ;
100
+
101
+ // SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call.
102
+ unsafe { panic_impl ( & pi) }
103
+ }
104
+
80
105
/// The entry point for panicking with a formatted message.
81
106
///
82
107
/// This is designed to reduce the amount of code required at the call
You can’t perform that action at this time.
0 commit comments