Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ macro_rules! unreachable {
#[rustc_diagnostic_opaque]
macro_rules! unimplemented {
() => {
$crate::panicking::panic("not implemented")
$crate::panic::unimplemented_noargs()
};
($($arg:tt)+) => {
$crate::panic!("not implemented: {}", $crate::format_args!($($arg)+))
Expand Down
35 changes: 31 additions & 4 deletions library/core/src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub use self::unwind_safe::{AssertUnwindSafe, RefUnwindSafe, UnwindSafe};
#[rustc_macro_transparency = "semiopaque"]
pub macro panic_2015 {
() => (
$crate::panicking::panic("explicit panic")
$crate::panic::panic_noargs()
),
($msg:literal $(,)?) => (
$crate::panicking::panic($msg)
Expand All @@ -49,7 +49,7 @@ pub macro panic_2015 {
#[rustc_macro_transparency = "semiopaque"]
pub macro panic_2021 {
() => (
$crate::panicking::panic("explicit panic")
$crate::panic::panic_noargs()
),
// Special-case the single-argument case for const_panic.
("{}", $arg:expr $(,)?) => ({
Expand All @@ -62,14 +62,23 @@ pub macro panic_2021 {
}),
}

#[doc(hidden)]
#[unstable(feature = "panic_internals", issue = "none")]
#[cold]
#[inline(never)]
#[track_caller]
pub const fn panic_noargs() -> ! {
crate::panicking::panic("explicit panic")
}

#[doc(hidden)]
#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
#[allow_internal_unstable(panic_internals)]
#[rustc_diagnostic_item = "unreachable_2015_macro"]
#[rustc_macro_transparency = "semiopaque"]
pub macro unreachable_2015 {
() => (
$crate::panicking::panic("internal error: entered unreachable code")
$crate::panic::unreachable_noargs()
),
// Use of `unreachable_display` for non_fmt_panic lint.
// NOTE: the message ("internal error ...") is embedded directly in unreachable_display
Expand All @@ -87,13 +96,31 @@ pub macro unreachable_2015 {
#[rustc_macro_transparency = "semiopaque"]
pub macro unreachable_2021 {
() => (
$crate::panicking::panic("internal error: entered unreachable code")
$crate::panic::unreachable_noargs()
),
($($t:tt)+) => (
$crate::panic!("internal error: entered unreachable code: {}", $crate::format_args!($($t)+))
),
}

#[doc(hidden)]
#[unstable(feature = "panic_internals", issue = "none")]
#[cold]
#[inline(never)]
#[track_caller]
pub const fn unreachable_noargs() -> ! {
crate::panicking::panic("internal error: entered unreachable code")
}

#[doc(hidden)]
#[unstable(feature = "panic_internals", issue = "none")]
#[cold]
#[inline(never)]
#[track_caller]
pub const fn unimplemented_noargs() -> ! {
crate::panicking::panic("not implemented")
}

/// Invokes a closure, aborting if the closure unwinds.
///
/// When compiled with aborting panics, this function is effectively a no-op.
Expand Down
Loading