Skip to content

Commit d82f10a

Browse files
committed
Address review feedback
1 parent 89d3b04 commit d82f10a

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

library/core/src/hint.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,12 @@ use crate::intrinsics;
9898
#[rustc_const_stable(feature = "const_unreachable_unchecked", since = "1.57.0")]
9999
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
100100
pub const unsafe fn unreachable_unchecked() -> ! {
101-
crate::panic::debug_assert_nounwind!(
102-
false,
103-
"hint::unreachable_unchecked must never be reached"
104-
);
105101
// SAFETY: the safety contract for `intrinsics::unreachable` must
106102
// be upheld by the caller.
107-
unsafe { intrinsics::unreachable() }
103+
unsafe {
104+
intrinsics::assert_unsafe_precondition!("hint::unreachable_unchecked must never be reached", () => false);
105+
intrinsics::unreachable()
106+
}
108107
}
109108

110109
/// Emits a machine instruction to signal the processor that it is running in

library/core/src/panic.rs

+5
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ pub macro unreachable_2021 {
9090
),
9191
}
9292

93+
/// Asserts that a boolean expression is `true`, and perform a non-unwinding panic otherwise.
94+
///
95+
/// This macro is similar to `debug_assert!`, but is intended to be used in code that should not
96+
/// unwind. For example, checks in `_unchecked` functions that are intended for debugging but should
97+
/// not compromise unwind safety.
9398
#[doc(hidden)]
9499
#[unstable(feature = "core_panic", issue = "none")]
95100
#[allow_internal_unstable(core_panic, const_format_args)]

library/core/src/panicking.rs

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
7979
#[rustc_nounwind]
8080
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
8181
pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>) -> ! {
82+
#[track_caller]
8283
fn runtime(fmt: fmt::Arguments<'_>) -> ! {
8384
if cfg!(feature = "panic_immediate_abort") {
8485
super::intrinsics::abort()
@@ -99,6 +100,7 @@ pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>) -> ! {
99100
}
100101

101102
#[inline]
103+
#[track_caller]
102104
const fn comptime(fmt: fmt::Arguments<'_>) -> ! {
103105
panic_fmt(fmt);
104106
}

0 commit comments

Comments
 (0)