@@ -84,12 +84,26 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
84
84
panic ! ( "index out of bounds: the len is {len} but the index is {index}" )
85
85
}
86
86
87
- // This function is called directly by the codegen backend, and must not have
88
- // any extra arguments (including those synthesized by track_caller).
87
+ /// Panic because we cannot unwind out of a function.
88
+ ///
89
+ /// This function is called directly by the codegen backend, and must not have
90
+ /// any extra arguments (including those synthesized by track_caller).
89
91
#[ cold]
90
- #[ inline( never) ]
91
92
#[ lang = "panic_no_unwind" ] // needed by codegen for panic in nounwind function
93
+ #[ cfg_attr( not( bootstrap) , rustc_nounwind) ]
94
+ #[ cfg_attr( bootstrap, rustc_allocator_nounwind) ]
92
95
fn panic_no_unwind ( ) -> ! {
96
+ panic_str_nounwind ( "panic in a function that cannot unwind" )
97
+ }
98
+
99
+ /// Like panic_fmt, but without unwinding and track_caller to reduce the impact on codesize.
100
+ /// Also just works on `str`, as a `fmt::Arguments` needs more space to be passed.
101
+ #[ cold]
102
+ #[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) ) ]
103
+ #[ cfg_attr( feature = "panic_immediate_abort" , inline) ]
104
+ #[ cfg_attr( not( bootstrap) , rustc_nounwind) ]
105
+ #[ cfg_attr( bootstrap, rustc_allocator_nounwind) ]
106
+ pub fn panic_str_nounwind ( msg : & ' static str ) -> ! {
93
107
if cfg ! ( feature = "panic_immediate_abort" ) {
94
108
super :: intrinsics:: abort ( )
95
109
}
@@ -102,7 +116,8 @@ fn panic_no_unwind() -> ! {
102
116
}
103
117
104
118
// PanicInfo with the `can_unwind` flag set to false forces an abort.
105
- let fmt = format_args ! ( "panic in a function that cannot unwind" ) ;
119
+ let pieces = [ msg] ;
120
+ let fmt = fmt:: Arguments :: new_v1 ( & pieces, & [ ] ) ;
106
121
let pi = PanicInfo :: internal_constructor ( Some ( & fmt) , Location :: caller ( ) , false ) ;
107
122
108
123
// SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call.
0 commit comments