Skip to content

Simplify expansion of panic!(). #140637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions library/core/src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,11 @@ pub macro panic_2021 {
#[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();
$crate::panicking::panic_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);
$crate::panicking::panic_display(&$arg);
}),
($($t:tt)+) => ({
// Semicolon to prevent temporaries inside the formatting machinery from
Expand Down
Loading