@@ -84,6 +84,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
84
84
#[ rustc_nounwind]
85
85
#[ rustc_const_unstable( feature = "core_panic" , issue = "none" ) ]
86
86
pub const fn panic_nounwind_fmt ( fmt : fmt:: Arguments < ' _ > , force_no_backtrace : bool ) -> ! {
87
+ #[ inline] // this should always be inlined into `panic_nounwind_fmt`
87
88
#[ track_caller]
88
89
fn runtime ( fmt : fmt:: Arguments < ' _ > , force_no_backtrace : bool ) -> ! {
89
90
if cfg ! ( feature = "panic_immediate_abort" ) {
@@ -112,6 +113,7 @@ pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: boo
112
113
#[ inline]
113
114
#[ track_caller]
114
115
const fn comptime ( fmt : fmt:: Arguments < ' _ > , _force_no_backtrace : bool ) -> ! {
116
+ // We don't unwind anyway at compile-time so we can call the regular `panic_fmt`.
115
117
panic_fmt ( fmt) ;
116
118
}
117
119
@@ -142,7 +144,8 @@ pub const fn panic(expr: &'static str) -> ! {
142
144
panic_fmt ( fmt:: Arguments :: new_const ( & [ expr] ) ) ;
143
145
}
144
146
145
- /// Like `panic`, but without unwinding and track_caller to reduce the impact on codesize.
147
+ /// Like `panic`, but without unwinding and track_caller to reduce the impact on codesize on the caller.
148
+ /// If you want `#[track_caller]` for nicer errors, call `panic_nounwind_fmt` directly.
146
149
#[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) , cold) ]
147
150
#[ cfg_attr( feature = "panic_immediate_abort" , inline) ]
148
151
#[ lang = "panic_nounwind" ] // needed by codegen for non-unwinding panics
@@ -205,8 +208,8 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
205
208
panic ! ( "index out of bounds: the len is {len} but the index is {index}" )
206
209
}
207
210
208
- #[ cold]
209
- #[ cfg_attr( not ( feature = "panic_immediate_abort" ) , inline( never ) ) ]
211
+ #[ cfg_attr ( not ( feature = "panic_immediate_abort" ) , inline ( never ) , cold) ]
212
+ #[ cfg_attr( feature = "panic_immediate_abort" , inline) ]
210
213
#[ track_caller]
211
214
#[ lang = "panic_misaligned_pointer_dereference" ] // needed by codegen for panic on misaligned pointer deref
212
215
#[ rustc_nounwind] // `CheckAlignment` MIR pass requires this function to never unwind
0 commit comments