mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Revert "Partially outline code inside the panic! macro".
Without any tests/benchmarks that show some improvement, it's hard to know whether the change had any positive effect at all. (And if it did, whether that effect is still achieved today.)
This commit is contained in:
@@ -827,7 +827,7 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
|
||||
|
||||
// At this point, we are calling a function, `callee`, whose `DefId` is known...
|
||||
|
||||
// `begin_panic` and `#[rustc_const_panic_str]` functions accept generic
|
||||
// `begin_panic` and `panic_display` functions accept generic
|
||||
// types other than str. Check to enforce that only str can be used in
|
||||
// const-eval.
|
||||
|
||||
@@ -841,8 +841,8 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
|
||||
return;
|
||||
}
|
||||
|
||||
// const-eval of `#[rustc_const_panic_str]` functions assumes the argument is `&&str`
|
||||
if tcx.has_attr(callee, sym::rustc_const_panic_str) {
|
||||
// const-eval of `panic_display` assumes the argument is `&&str`
|
||||
if tcx.is_lang_item(callee, LangItem::PanicDisplay) {
|
||||
match args[0].node.ty(&self.ccx.body.local_decls, tcx).kind() {
|
||||
ty::Ref(_, ty, _) if matches!(ty.kind(), ty::Ref(_, ty, _) if ty.is_str()) =>
|
||||
{}
|
||||
|
||||
@@ -237,7 +237,7 @@ fn hook_special_const_fn(
|
||||
) -> InterpResult<'tcx, Option<ty::Instance<'tcx>>> {
|
||||
let def_id = instance.def_id();
|
||||
|
||||
if self.tcx.has_attr(def_id, sym::rustc_const_panic_str)
|
||||
if self.tcx.is_lang_item(def_id, LangItem::PanicDisplay)
|
||||
|| self.tcx.is_lang_item(def_id, LangItem::BeginPanic)
|
||||
{
|
||||
let args = self.copy_fn_args(args);
|
||||
|
||||
@@ -929,10 +929,6 @@ pub struct BuiltinAttribute {
|
||||
rustc_do_not_const_check, Normal, template!(Word), WarnFollowing,
|
||||
EncodeCrossCrate::Yes, "`#[rustc_do_not_const_check]` skips const-check for this function's body",
|
||||
),
|
||||
rustc_attr!(
|
||||
rustc_const_panic_str, Normal, template!(Word), WarnFollowing,
|
||||
EncodeCrossCrate::Yes, "`#[rustc_const_panic_str]` ensures the argument to this function is &&str during const-check",
|
||||
),
|
||||
rustc_attr!(
|
||||
rustc_const_stable_indirect, Normal,
|
||||
template!(Word),
|
||||
|
||||
@@ -286,6 +286,7 @@ pub fn extract(attrs: &[impl AttributeExt]) -> Option<(Symbol, Span)> {
|
||||
Panic, sym::panic, panic_fn, Target::Fn, GenericRequirement::Exact(0);
|
||||
PanicNounwind, sym::panic_nounwind, panic_nounwind, Target::Fn, GenericRequirement::Exact(0);
|
||||
PanicFmt, sym::panic_fmt, panic_fmt, Target::Fn, GenericRequirement::None;
|
||||
PanicDisplay, sym::panic_display, panic_display, Target::Fn, GenericRequirement::None;
|
||||
ConstPanicFmt, sym::const_panic_fmt, const_panic_fmt, Target::Fn, GenericRequirement::None;
|
||||
PanicBoundsCheck, sym::panic_bounds_check, panic_bounds_check_fn, Target::Fn, GenericRequirement::Exact(0);
|
||||
PanicMisalignedPointerDereference, sym::panic_misaligned_pointer_dereference, panic_misaligned_pointer_dereference_fn, Target::Fn, GenericRequirement::Exact(0);
|
||||
|
||||
@@ -1583,6 +1583,7 @@
|
||||
panic_const_shl_overflow,
|
||||
panic_const_shr_overflow,
|
||||
panic_const_sub_overflow,
|
||||
panic_display,
|
||||
panic_fmt,
|
||||
panic_handler,
|
||||
panic_impl,
|
||||
@@ -1828,7 +1829,6 @@
|
||||
rustc_coherence_is_core,
|
||||
rustc_coinductive,
|
||||
rustc_confusables,
|
||||
rustc_const_panic_str,
|
||||
rustc_const_stable,
|
||||
rustc_const_stable_indirect,
|
||||
rustc_const_unstable,
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
#[allow_internal_unstable(panic_internals, const_format_args)]
|
||||
#[rustc_diagnostic_item = "core_panic_2021_macro"]
|
||||
#[rustc_macro_transparency = "semitransparent"]
|
||||
#[cfg(feature = "panic_immediate_abort")]
|
||||
pub macro panic_2021 {
|
||||
() => (
|
||||
$crate::panicking::panic("explicit panic")
|
||||
@@ -64,50 +63,6 @@
|
||||
}),
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[unstable(feature = "edition_panic", issue = "none", reason = "use panic!() instead")]
|
||||
#[allow_internal_unstable(
|
||||
panic_internals,
|
||||
core_intrinsics,
|
||||
const_dispatch,
|
||||
const_eval_select,
|
||||
const_format_args,
|
||||
rustc_attrs
|
||||
)]
|
||||
#[rustc_diagnostic_item = "core_panic_2021_macro"]
|
||||
#[rustc_macro_transparency = "semitransparent"]
|
||||
#[cfg(not(feature = "panic_immediate_abort"))]
|
||||
pub macro panic_2021 {
|
||||
() => ({
|
||||
// Create a function so that the argument for `track_caller`
|
||||
// can be moved inside if possible.
|
||||
#[cold]
|
||||
#[track_caller]
|
||||
#[inline(never)]
|
||||
const fn panic_cold_explicit() -> ! {
|
||||
$crate::panicking::panic_explicit()
|
||||
}
|
||||
panic_cold_explicit();
|
||||
}),
|
||||
// Special-case the single-argument case for const_panic.
|
||||
("{}", $arg:expr $(,)?) => ({
|
||||
#[cold]
|
||||
#[track_caller]
|
||||
#[inline(never)]
|
||||
#[rustc_const_panic_str] // enforce a &&str argument in const-check and hook this by const-eval
|
||||
#[rustc_do_not_const_check] // hooked by const-eval
|
||||
const fn panic_cold_display<T: $crate::fmt::Display>(arg: &T) -> ! {
|
||||
$crate::panicking::panic_display(arg)
|
||||
}
|
||||
panic_cold_display(&$arg);
|
||||
}),
|
||||
($($t:tt)+) => ({
|
||||
// Semicolon to prevent temporaries inside the formatting machinery from
|
||||
// being considered alive in the caller after the panic_fmt call.
|
||||
$crate::panicking::panic_fmt($crate::const_format_args!($($t)+));
|
||||
}),
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
|
||||
#[allow_internal_unstable(panic_internals)]
|
||||
|
||||
@@ -233,14 +233,6 @@ pub fn panic_nounwind_nobacktrace(expr: &'static str) -> ! {
|
||||
panic_nounwind_fmt(fmt::Arguments::new_const(&[expr]), /* force_no_backtrace */ true);
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
|
||||
#[cfg_attr(feature = "panic_immediate_abort", inline)]
|
||||
#[rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable
|
||||
pub const fn panic_explicit() -> ! {
|
||||
panic_display(&"explicit panic");
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[rustc_diagnostic_item = "unreachable_display"] // needed for `non-fmt-panics` lint
|
||||
@@ -260,9 +252,8 @@ pub const fn panic_str_2015(expr: &str) -> ! {
|
||||
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[lang = "panic_display"] // needed for const-evaluated panics
|
||||
#[rustc_do_not_const_check] // hooked by const-eval
|
||||
// enforce a &&str argument in const-check and hook this by const-eval
|
||||
#[rustc_const_panic_str]
|
||||
#[rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable
|
||||
pub const fn panic_display<T: fmt::Display>(x: &T) -> ! {
|
||||
panic_fmt(format_args!("{}", *x));
|
||||
|
||||
@@ -250,18 +250,13 @@ pub fn parse(expr: &'a Expr<'a>) -> Option<Self> {
|
||||
};
|
||||
let name = path.segments.last().unwrap().ident.name;
|
||||
|
||||
// This has no argument
|
||||
if name == sym::panic_cold_explicit {
|
||||
return Some(Self::Empty);
|
||||
}
|
||||
|
||||
let [arg, rest @ ..] = args else {
|
||||
return None;
|
||||
};
|
||||
let result = match name {
|
||||
sym::panic if arg.span.eq_ctxt(expr.span) => Self::Empty,
|
||||
sym::panic | sym::panic_str => Self::Str(arg),
|
||||
sym::panic_display | sym::panic_cold_display => {
|
||||
sym::panic_display => {
|
||||
let ExprKind::AddrOf(_, _, e) = &arg.kind else {
|
||||
return None;
|
||||
};
|
||||
|
||||
@@ -241,9 +241,6 @@ macro_rules! generate {
|
||||
or_insert,
|
||||
or_insert_with,
|
||||
outer_expn,
|
||||
panic_cold_display,
|
||||
panic_cold_explicit,
|
||||
panic_display,
|
||||
panic_str,
|
||||
parse,
|
||||
partition,
|
||||
|
||||
Reference in New Issue
Block a user