Skip to content

Commit 81cd49d

Browse files
committed
Address review feedback
1 parent 97c1502 commit 81cd49d

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
@@ -139,6 +139,11 @@ pub macro unreachable_2021 {
139139
),
140140
}
141141

142+
/// Asserts that a boolean expression is `true`, and perform a non-unwinding panic otherwise.
143+
///
144+
/// This macro is similar to `debug_assert!`, but is intended to be used in code that should not
145+
/// unwind. For example, checks in `_unchecked` functions that are intended for debugging but should
146+
/// not compromise unwind safety.
142147
#[doc(hidden)]
143148
#[unstable(feature = "core_panic", issue = "none")]
144149
#[allow_internal_unstable(core_panic, const_format_args)]

library/core/src/panicking.rs

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
8484
#[rustc_nounwind]
8585
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
8686
pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: bool) -> ! {
87+
#[track_caller]
8788
fn runtime(fmt: fmt::Arguments<'_>, force_no_backtrace: bool) -> ! {
8889
if cfg!(feature = "panic_immediate_abort") {
8990
super::intrinsics::abort()
@@ -109,6 +110,7 @@ pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: boo
109110
}
110111

111112
#[inline]
113+
#[track_caller]
112114
const fn comptime(fmt: fmt::Arguments<'_>, _force_no_backtrace: bool) -> ! {
113115
panic_fmt(fmt);
114116
}

0 commit comments

Comments
 (0)