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 2e2642e

Browse files
committed
Auto merge of #145304 - m-ou-se:simplify-panic, r=oli-obk
Revert "Partially outline code inside the panic! macro". This reverts #115670 Without any tests/benchmarks that show some improvement, it's hard to know whether the change had any positive effect. (And if it did, whether that effect is still achieved today.)
2 parents 1ae7c49 + 08acba3 commit 2e2642e

File tree

9 files changed

+8
-73
lines changed

9 files changed

+8
-73
lines changed

‎compiler/rustc_const_eval/src/check_consts/check.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
827827

828828
// At this point, we are calling a function, `callee`, whose `DefId` is known...
829829

830-
// `begin_panic` and `#[rustc_const_panic_str]` functions accept generic
830+
// `begin_panic` and `panic_display` functions accept generic
831831
// types other than str. Check to enforce that only str can be used in
832832
// const-eval.
833833

@@ -841,8 +841,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
841841
return;
842842
}
843843

844-
// const-eval of `#[rustc_const_panic_str]` functions assumes the argument is `&&str`
845-
if tcx.has_attr(callee, sym::rustc_const_panic_str) {
844+
// const-eval of `panic_display` assumes the argument is `&&str`
845+
if tcx.is_lang_item(callee, LangItem::PanicDisplay) {
846846
match args[0].node.ty(&self.ccx.body.local_decls, tcx).kind() {
847847
ty::Ref(_, ty, _) if matches!(ty.kind(), ty::Ref(_, ty, _) if ty.is_str()) =>
848848
{}

‎compiler/rustc_const_eval/src/const_eval/machine.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
237237
) -> InterpResult<'tcx, Option<ty::Instance<'tcx>>> {
238238
let def_id = instance.def_id();
239239

240-
if self.tcx.has_attr(def_id, sym::rustc_const_panic_str)
240+
if self.tcx.is_lang_item(def_id, LangItem::PanicDisplay)
241241
|| self.tcx.is_lang_item(def_id, LangItem::BeginPanic)
242242
{
243243
let args = self.copy_fn_args(args);

‎compiler/rustc_feature/src/builtin_attrs.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,10 +1158,6 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
11581158
rustc_do_not_const_check, Normal, template!(Word), WarnFollowing,
11591159
EncodeCrossCrate::Yes, "`#[rustc_do_not_const_check]` skips const-check for this function's body",
11601160
),
1161-
rustc_attr!(
1162-
rustc_const_panic_str, Normal, template!(Word), WarnFollowing,
1163-
EncodeCrossCrate::Yes, "`#[rustc_const_panic_str]` ensures the argument to this function is &&str during const-check",
1164-
),
11651161
rustc_attr!(
11661162
rustc_const_stable_indirect, Normal,
11671163
template!(Word),

‎compiler/rustc_hir/src/lang_items.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ language_item_table! {
286286
Panic, sym::panic, panic_fn, Target::Fn, GenericRequirement::Exact(0);
287287
PanicNounwind, sym::panic_nounwind, panic_nounwind, Target::Fn, GenericRequirement::Exact(0);
288288
PanicFmt, sym::panic_fmt, panic_fmt, Target::Fn, GenericRequirement::None;
289+
PanicDisplay, sym::panic_display, panic_display, Target::Fn, GenericRequirement::None;
289290
ConstPanicFmt, sym::const_panic_fmt, const_panic_fmt, Target::Fn, GenericRequirement::None;
290291
PanicBoundsCheck, sym::panic_bounds_check, panic_bounds_check_fn, Target::Fn, GenericRequirement::Exact(0);
291292
PanicMisalignedPointerDereference, sym::panic_misaligned_pointer_dereference, panic_misaligned_pointer_dereference_fn, Target::Fn, GenericRequirement::Exact(0);

‎compiler/rustc_span/src/symbol.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,7 @@ symbols! {
15931593
panic_const_shl_overflow,
15941594
panic_const_shr_overflow,
15951595
panic_const_sub_overflow,
1596+
panic_display,
15961597
panic_fmt,
15971598
panic_handler,
15981599
panic_impl,
@@ -1838,7 +1839,6 @@ symbols! {
18381839
rustc_coherence_is_core,
18391840
rustc_coinductive,
18401841
rustc_confusables,
1841-
rustc_const_panic_str,
18421842
rustc_const_stable,
18431843
rustc_const_stable_indirect,
18441844
rustc_const_unstable,

‎library/core/src/panic.rs‎

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub macro panic_2015 {
4848
#[allow_internal_unstable(panic_internals, const_format_args)]
4949
#[rustc_diagnostic_item = "core_panic_2021_macro"]
5050
#[rustc_macro_transparency = "semitransparent"]
51-
#[cfg(feature = "panic_immediate_abort")]
5251
pub macro panic_2021 {
5352
() => (
5453
$crate::panicking::panic("explicit panic")
@@ -64,50 +63,6 @@ pub macro panic_2021 {
6463
}),
6564
}
6665

67-
#[doc(hidden)]
68-
#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
69-
#[allow_internal_unstable(
70-
panic_internals,
71-
core_intrinsics,
72-
const_dispatch,
73-
const_eval_select,
74-
const_format_args,
75-
rustc_attrs
76-
)]
77-
#[rustc_diagnostic_item = "core_panic_2021_macro"]
78-
#[rustc_macro_transparency = "semitransparent"]
79-
#[cfg(not(feature = "panic_immediate_abort"))]
80-
pub macro panic_2021 {
81-
() => ({
82-
// Create a function so that the argument for `track_caller`
83-
// can be moved inside if possible.
84-
#[cold]
85-
#[track_caller]
86-
#[inline(never)]
87-
const fn panic_cold_explicit() -> ! {
88-
$crate::panicking::panic_explicit()
89-
}
90-
panic_cold_explicit();
91-
}),
92-
// Special-case the single-argument case for const_panic.
93-
("{}", $arg:expr $(,)?) => ({
94-
#[cold]
95-
#[track_caller]
96-
#[inline(never)]
97-
#[rustc_const_panic_str] // enforce a &&str argument in const-check and hook this by const-eval
98-
#[rustc_do_not_const_check] // hooked by const-eval
99-
const fn panic_cold_display<T: $crate::fmt::Display>(arg: &T) -> ! {
100-
$crate::panicking::panic_display(arg)
101-
}
102-
panic_cold_display(&$arg);
103-
}),
104-
($($t:tt)+) => ({
105-
// Semicolon to prevent temporaries inside the formatting machinery from
106-
// being considered alive in the caller after the panic_fmt call.
107-
$crate::panicking::panic_fmt($crate::const_format_args!($($t)+));
108-
}),
109-
}
110-
11166
#[doc(hidden)]
11267
#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
11368
#[allow_internal_unstable(panic_internals)]

‎library/core/src/panicking.rs‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,6 @@ pub fn panic_nounwind_nobacktrace(expr: &'static str) -> ! {
233233
panic_nounwind_fmt(fmt::Arguments::new_const(&[expr]), /* force_no_backtrace */ true);
234234
}
235235

236-
#[track_caller]
237-
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
238-
#[cfg_attr(feature = "panic_immediate_abort", inline)]
239-
#[rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable
240-
pub const fn panic_explicit() -> ! {
241-
panic_display(&"explicit panic");
242-
}
243-
244236
#[inline]
245237
#[track_caller]
246238
#[rustc_diagnostic_item = "unreachable_display"] // needed for `non-fmt-panics` lint
@@ -260,9 +252,8 @@ pub const fn panic_str_2015(expr: &str) -> ! {
260252

261253
#[inline]
262254
#[track_caller]
255+
#[lang = "panic_display"] // needed for const-evaluated panics
263256
#[rustc_do_not_const_check] // hooked by const-eval
264-
// enforce a &&str argument in const-check and hook this by const-eval
265-
#[rustc_const_panic_str]
266257
#[rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable
267258
pub const fn panic_display<T: fmt::Display>(x: &T) -> ! {
268259
panic_fmt(format_args!("{}", *x));

‎src/tools/clippy/clippy_utils/src/macros.rs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,13 @@ impl<'a> PanicExpn<'a> {
250250
};
251251
let name = path.segments.last().unwrap().ident.name;
252252

253-
// This has no argument
254-
if name == sym::panic_cold_explicit {
255-
return Some(Self::Empty);
256-
}
257-
258253
let [arg, rest @ ..] = args else {
259254
return None;
260255
};
261256
let result = match name {
262257
sym::panic if arg.span.eq_ctxt(expr.span) => Self::Empty,
263258
sym::panic | sym::panic_str => Self::Str(arg),
264-
sym::panic_display | sym::panic_cold_display => {
259+
sym::panic_display => {
265260
let ExprKind::AddrOf(_, _, e) = &arg.kind else {
266261
return None;
267262
};

‎src/tools/clippy/clippy_utils/src/sym.rs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,6 @@ generate! {
241241
or_insert,
242242
or_insert_with,
243243
outer_expn,
244-
panic_cold_display,
245-
panic_cold_explicit,
246-
panic_display,
247244
panic_str,
248245
parse,
249246
partition,

0 commit comments

Comments
(0)

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