diff options
| author | bors <bors@rust-lang.org> | 2023-12-05 12:05:22 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-12-05 12:05:22 +0000 | 
| commit | 154f645d76a9752bd7ea58d7382b2e90e83557fb (patch) | |
| tree | 5164ad71a4e045f38398dd2526df238e0d51beab | |
| parent | f536185ed8fe11d45da662c8575f4253fede3986 (diff) | |
| parent | 8de5bd0f6eb389c55d5e96a18ef21c5d025fce9f (diff) | |
| download | rust-154f645d76a9752bd7ea58d7382b2e90e83557fb.tar.gz rust-154f645d76a9752bd7ea58d7382b2e90e83557fb.zip | |
Auto merge of #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 https://github.com/rust-lang/rust/pull/110303.
| -rw-r--r-- | library/core/src/panicking.rs | 9 | 
1 files changed, 6 insertions, 3 deletions
| diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index 553e18c6883..1b6e77b96b1 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -84,6 +84,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! { #[rustc_nounwind] #[rustc_const_unstable(feature = "core_panic", issue = "none")] pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: bool) -> ! { + #[inline] // this should always be inlined into `panic_nounwind_fmt` #[track_caller] fn runtime(fmt: fmt::Arguments<'_>, force_no_backtrace: bool) -> ! { if cfg!(feature = "panic_immediate_abort") { @@ -112,6 +113,7 @@ pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: boo #[inline] #[track_caller] const fn comptime(fmt: fmt::Arguments<'_>, _force_no_backtrace: bool) -> ! { + // We don't unwind anyway at compile-time so we can call the regular `panic_fmt`. panic_fmt(fmt); } @@ -142,7 +144,8 @@ pub const fn panic(expr: &'static str) -> ! { panic_fmt(fmt::Arguments::new_const(&[expr])); } -/// Like `panic`, but without unwinding and track_caller to reduce the impact on codesize. +/// Like `panic`, but without unwinding and track_caller to reduce the impact on codesize on the caller. +/// If you want `#[track_caller]` for nicer errors, call `panic_nounwind_fmt` directly. #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)] #[cfg_attr(feature = "panic_immediate_abort", inline)] #[lang = "panic_nounwind"] // needed by codegen for non-unwinding panics @@ -205,8 +208,8 @@ fn panic_bounds_check(index: usize, len: usize) -> ! { panic!("index out of bounds: the len is {len} but the index is {index}") } -#[cold] -#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] +#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)] +#[cfg_attr(feature = "panic_immediate_abort", inline)] #[track_caller] #[lang = "panic_misaligned_pointer_dereference"] // needed by codegen for panic on misaligned pointer deref #[rustc_nounwind] // `CheckAlignment` MIR pass requires this function to never unwind | 
