From 20f26d41c419d5df1edd5fa442b45723ecf5f970 Mon Sep 17 00:00:00 2001 From: cbrownsey Date: Mon, 1 Aug 2022 23:34:59 +1200 Subject: [PATCH] made `unreachable_unchecked` panic in debug mode --- library/core/src/hint.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/core/src/hint.rs b/library/core/src/hint.rs index 81b6d5737ea75..25a76be13cc56 100644 --- a/library/core/src/hint.rs +++ b/library/core/src/hint.rs @@ -98,9 +98,13 @@ use crate::intrinsics; #[rustc_const_stable(feature = "const_unreachable_unchecked", since = "1.57.0")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn unreachable_unchecked() -> ! { - // SAFETY: the safety contract for `intrinsics::unreachable` must - // be upheld by the caller. - unsafe { intrinsics::unreachable() } + if cfg!(debug_assertions) { + unreachable!() + } else { + // SAFETY: the safety contract for `intrinsics::unreachable` must + // be upheld by the caller. + unsafe { intrinsics::unreachable() } + } } /// Emits a machine instruction to signal the processor that it is running in