Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 154f645

Browse files
committed
Auto merge of rust-lang#118362 - RalfJung:panic_nounwind, r=thomcc
make sure panic_nounwind_fmt can still be fully inlined (e.g. for panic_immediate_abort) Follow-up to rust-lang#110303.
2 parents f536185 + 8de5bd0 commit 154f645

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

‎library/core/src/panicking.rs‎

Lines changed: 6 additions & 3 deletions
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
@@ -205,8 +208,8 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
205208
panic!("index out of bounds: the len is {len} but the index is {index}")
206209
}
207210

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)]
210213
#[track_caller]
211214
#[lang = "panic_misaligned_pointer_dereference"] // needed by codegen for panic on misaligned pointer deref
212215
#[rustc_nounwind] // `CheckAlignment` MIR pass requires this function to never unwind

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /