Skip to content

Commit 2a48a77

Browse files
committed
make sure panic_nounwind_fmt can still be fully inlined (e.g. for panic_immediate_abort)
1 parent a191610 commit 2a48a77

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

library/core/src/panicking.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
8484
#[rustc_nounwind]
8585
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
8686
pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: bool) -> ! {
87+
#[inline] // this should always be inlined into `panic_nounwind_fmt`
8788
#[track_caller]
8889
fn runtime(fmt: fmt::Arguments<'_>, force_no_backtrace: bool) -> ! {
8990
if cfg!(feature = "panic_immediate_abort") {
@@ -112,6 +113,7 @@ pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: boo
112113
#[inline]
113114
#[track_caller]
114115
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`.
115117
panic_fmt(fmt);
116118
}
117119

@@ -142,7 +144,8 @@ pub const fn panic(expr: &'static str) -> ! {
142144
panic_fmt(fmt::Arguments::new_const(&[expr]));
143145
}
144146

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.
146149
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
147150
#[cfg_attr(feature = "panic_immediate_abort", inline)]
148151
#[lang = "panic_nounwind"] // needed by codegen for non-unwinding panics

0 commit comments

Comments
 (0)