Skip to content

Commit f702499

Browse files
authored
Rollup merge of #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 84fe598 + 7bd93df commit f702499

File tree

12 files changed

+15
-38
lines changed

12 files changed

+15
-38
lines changed

compiler/rustc_const_eval/src/const_eval/machine.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
7272
let span = self.find_closest_untracked_caller_location();
7373
let (file, line, col) = self.location_triple_for_span(span);
7474
return Err(ConstEvalErrKind::Panic { msg, file, line, col }.into());
75-
} else if Some(def_id) == self.tcx.lang_items().panic_fmt()
76-
|| Some(def_id) == self.tcx.lang_items().begin_panic_fmt()
77-
{
75+
} else if Some(def_id) == self.tcx.lang_items().panic_fmt() {
7876
// For panic_fmt, call const_panic_fmt instead.
7977
if let Some(const_panic_fmt) = self.tcx.lang_items().const_panic_fmt() {
8078
return Ok(Some(

compiler/rustc_const_eval/src/transform/check_consts/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ pub fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
7979
|| Some(def_id) == tcx.lang_items().panic_display()
8080
|| Some(def_id) == tcx.lang_items().begin_panic_fn()
8181
|| Some(def_id) == tcx.lang_items().panic_fmt()
82-
|| Some(def_id) == tcx.lang_items().begin_panic_fmt()
8382
}
8483

8584
/// Returns `true` if this `DefId` points to one of the lang items that will be handled differently

compiler/rustc_hir/src/lang_items.rs

-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ language_item_table! {
292292
PanicImpl, sym::panic_impl, panic_impl, Target::Fn, GenericRequirement::None;
293293
/// libstd panic entry point. Necessary for const eval to be able to catch it
294294
BeginPanic, sym::begin_panic, begin_panic_fn, Target::Fn, GenericRequirement::None;
295-
BeginPanicFmt, sym::begin_panic_fmt, begin_panic_fmt, Target::Fn, GenericRequirement::None;
296295

297296
ExchangeMalloc, sym::exchange_malloc, exchange_malloc_fn, Target::Fn, GenericRequirement::None;
298297
BoxFree, sym::box_free, box_free_fn, Target::Fn, GenericRequirement::Minimum(1);

compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ symbols! {
355355
await_macro,
356356
bang,
357357
begin_panic,
358-
begin_panic_fmt,
359358
bench,
360359
bin,
361360
bind_by_move_pattern_guards,

library/core/src/panic/panic_info.rs

+1-1
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
}

library/core/src/panicking.rs

+8-1
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]

library/std/src/panic.rs

+1-1
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

library/std/src/panicking.rs

+2-24
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>,

library/std/src/rt.rs

+2-2
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;

src/tools/clippy/clippy_utils/src/higher.rs

-1
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,6 @@ impl PanicExpn<'tcx> {
619619
if let Some(init) = block.expr;
620620
if let ExprKind::Call(_, [format_args]) = init.kind;
621621
let expn_data = expr.span.ctxt().outer_expn_data();
622-
if let ExprKind::AddrOf(_, _, format_args) = format_args.kind;
623622
if let Some(format_args) = FormatArgsExpn::parse(format_args);
624623
then {
625624
Some(PanicExpn {

src/tools/clippy/clippy_utils/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,6 @@ pub fn match_panic_def_id(cx: &LateContext<'_>, did: DefId) -> bool {
16461646
did,
16471647
&[
16481648
&paths::BEGIN_PANIC,
1649-
&paths::BEGIN_PANIC_FMT,
16501649
&paths::PANIC_ANY,
16511650
&paths::PANICKING_PANIC,
16521651
&paths::PANICKING_PANIC_FMT,

src/tools/clippy/clippy_utils/src/paths.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub const ARC_PTR_EQ: [&str; 4] = ["alloc", "sync", "Arc", "ptr_eq"];
2020
pub const ASMUT_TRAIT: [&str; 3] = ["core", "convert", "AsMut"];
2121
pub const ASREF_TRAIT: [&str; 3] = ["core", "convert", "AsRef"];
2222
pub(super) const BEGIN_PANIC: [&str; 3] = ["std", "panicking", "begin_panic"];
23-
pub(super) const BEGIN_PANIC_FMT: [&str; 3] = ["std", "panicking", "begin_panic_fmt"];
2423
/// Preferably use the diagnostic item `sym::Borrow` where possible
2524
pub const BORROW_TRAIT: [&str; 3] = ["core", "borrow", "Borrow"];
2625
pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"];

0 commit comments

Comments
 (0)