Skip to content

Commit 677f92d

Browse files
authored
Rollup merge of rust-lang#88860 - nbdd0121:panic, r=m-ou-se
Deduplicate panic_fmt std's begin_panic_fmt and core's panic_fmt are duplicates. Merge them to declutter code and remove a lang item.
2 parents c03d258 + 75e8fe1 commit 677f92d

File tree

5 files changed

+14
-29
lines changed

5 files changed

+14
-29
lines changed

core/src/panic/panic_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'a> PanicInfo<'a> {
121121
#[stable(feature = "panic_hooks", since = "1.10.0")]
122122
pub fn location(&self) -> Option<&Location<'_>> {
123123
// NOTE: If this is changed to sometimes return None,
124-
// deal with that case in std::panicking::default_hook and std::panicking::begin_panic_fmt.
124+
// deal with that case in std::panicking::default_hook and core::panicking::panic_fmt.
125125
Some(&self.location)
126126
}
127127
}

core/src/panicking.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,15 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
7676
panic!("index out of bounds: the len is {} but the index is {}", len, index)
7777
}
7878

79-
/// The underlying implementation of libcore's `panic!` macro when formatting is used.
79+
/// The entry point for panicking with a formatted message.
80+
///
81+
/// This is designed to reduce the amount of code required at the call
82+
/// site as much as possible (so that `panic!()` has as low an impact
83+
/// on (e.g.) the inlining of other functions as possible), by moving
84+
/// the actual formatting into this shared place.
8085
#[cold]
86+
// If panic_immediate_abort, inline the abort call,
87+
// otherwise avoid inlining because of it is cold path.
8188
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
8289
#[cfg_attr(feature = "panic_immediate_abort", inline)]
8390
#[track_caller]

std/src/panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub macro panic_2015 {
2525
$crate::rt::panic_display(&$arg)
2626
}),
2727
($fmt:expr, $($arg:tt)+) => ({
28-
$crate::rt::begin_panic_fmt(&$crate::const_format_args!($fmt, $($arg)+))
28+
$crate::rt::panic_fmt($crate::const_format_args!($fmt, $($arg)+))
2929
}),
3030
}
3131

std/src/panicking.rs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -437,31 +437,9 @@ pub fn panicking() -> bool {
437437
!panic_count::count_is_zero()
438438
}
439439

440-
/// The entry point for panicking with a formatted message.
441-
///
442-
/// This is designed to reduce the amount of code required at the call
443-
/// site as much as possible (so that `panic!()` has as low an impact
444-
/// on (e.g.) the inlining of other functions as possible), by moving
445-
/// the actual formatting into this shared place.
446-
#[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")]
447-
#[cold]
448-
// If panic_immediate_abort, inline the abort call,
449-
// otherwise avoid inlining because of it is cold path.
450-
#[cfg_attr(not(feature = "panic_immediate_abort"), track_caller)]
451-
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
452-
#[cfg_attr(feature = "panic_immediate_abort", inline)]
453-
#[cfg_attr(not(test), lang = "begin_panic_fmt")]
454-
pub fn begin_panic_fmt(msg: &fmt::Arguments<'_>) -> ! {
455-
if cfg!(feature = "panic_immediate_abort") {
456-
intrinsics::abort()
457-
}
458-
459-
let info = PanicInfo::internal_constructor(Some(msg), Location::caller());
460-
begin_panic_handler(&info)
461-
}
462-
463440
/// Entry point of panics from the libcore crate (`panic_impl` lang item).
464-
#[cfg_attr(not(test), panic_handler)]
441+
#[cfg(not(test))]
442+
#[panic_handler]
465443
pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
466444
struct PanicPayload<'a> {
467445
inner: &'a fmt::Arguments<'a>,

std/src/rt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use crate::ffi::CString;
2020

2121
// Re-export some of our utilities which are expected by other crates.
22-
pub use crate::panicking::{begin_panic, begin_panic_fmt, panic_count};
23-
pub use core::panicking::panic_display;
22+
pub use crate::panicking::{begin_panic, panic_count};
23+
pub use core::panicking::{panic_display, panic_fmt};
2424

2525
use crate::sync::Once;
2626
use crate::sys;

0 commit comments

Comments
 (0)