Skip to content

Commit d751558

Browse files
committed
Revert "Rollup merge of #88860 - nbdd0121:panic, r=m-ou-se"
This reverts commit f702499, reversing changes made to 84fe598.
1 parent 47aeac6 commit d751558

File tree

12 files changed

+38
-15
lines changed

12 files changed

+38
-15
lines changed

compiler/rustc_const_eval/src/const_eval/machine.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ 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() {
75+
} else if Some(def_id) == self.tcx.lang_items().panic_fmt()
76+
|| Some(def_id) == self.tcx.lang_items().begin_panic_fmt()
77+
{
7678
// For panic_fmt, call const_panic_fmt instead.
7779
if let Some(const_panic_fmt) = self.tcx.lang_items().const_panic_fmt() {
7880
return Ok(Some(

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

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ 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()
8283
}
8384

8485
/// 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,6 +292,7 @@ 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;
295296

296297
ExchangeMalloc, sym::exchange_malloc, exchange_malloc_fn, Target::Fn, GenericRequirement::None;
297298
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,6 +355,7 @@ symbols! {
355355
await_macro,
356356
bang,
357357
begin_panic,
358+
begin_panic_fmt,
358359
bench,
359360
bin,
360361
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 core::panicking::panic_fmt.
124+
// deal with that case in std::panicking::default_hook and std::panicking::begin_panic_fmt.
125125
Some(&self.location)
126126
}
127127
}

library/core/src/panicking.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,8 @@ 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 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.
79+
/// The underlying implementation of libcore's `panic!` macro when formatting is used.
8580
#[cold]
86-
// If panic_immediate_abort, inline the abort call,
87-
// otherwise avoid inlining because of it is cold path.
8881
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
8982
#[cfg_attr(feature = "panic_immediate_abort", inline)]
9083
#[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::panic_fmt($crate::const_format_args!($fmt, $($arg)+))
28+
$crate::rt::begin_panic_fmt(&$crate::const_format_args!($fmt, $($arg)+))
2929
}),
3030
}
3131

library/std/src/panicking.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,31 @@ 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+
440463
/// Entry point of panics from the libcore crate (`panic_impl` lang item).
441-
#[cfg(not(test))]
442-
#[panic_handler]
464+
#[cfg_attr(not(test), panic_handler)]
443465
pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
444466
struct PanicPayload<'a> {
445467
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, panic_count};
23-
pub use core::panicking::{panic_display, panic_fmt};
22+
pub use crate::panicking::{begin_panic, begin_panic_fmt, panic_count};
23+
pub use core::panicking::panic_display;
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
@@ -722,6 +722,7 @@ impl PanicExpn<'tcx> {
722722
if let Some(init) = block.expr;
723723
if let ExprKind::Call(_, [format_args]) = init.kind;
724724
let expn_data = expr.span.ctxt().outer_expn_data();
725+
if let ExprKind::AddrOf(_, _, format_args) = format_args.kind;
725726
if let Some(format_args) = FormatArgsExpn::parse(format_args);
726727
then {
727728
Some(PanicExpn {

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

+1
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,7 @@ pub fn match_panic_def_id(cx: &LateContext<'_>, did: DefId) -> bool {
16411641
did,
16421642
&[
16431643
&paths::BEGIN_PANIC,
1644+
&paths::BEGIN_PANIC_FMT,
16441645
&paths::PANIC_ANY,
16451646
&paths::PANICKING_PANIC,
16461647
&paths::PANICKING_PANIC_FMT,

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

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub const ASSERT_NE_MACRO: [&str; 3] = ["core", "macros", "assert_ne"];
2626
pub const ASMUT_TRAIT: [&str; 3] = ["core", "convert", "AsMut"];
2727
pub const ASREF_TRAIT: [&str; 3] = ["core", "convert", "AsRef"];
2828
pub(super) const BEGIN_PANIC: [&str; 3] = ["std", "panicking", "begin_panic"];
29+
pub(super) const BEGIN_PANIC_FMT: [&str; 3] = ["std", "panicking", "begin_panic_fmt"];
2930
/// Preferably use the diagnostic item `sym::Borrow` where possible
3031
pub const BORROW_TRAIT: [&str; 3] = ["core", "borrow", "Borrow"];
3132
pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"];

0 commit comments

Comments
 (0)