Skip to content

Commit 4fefa2c

Browse files
committed
Make unreachable_unchecked a const fn
1 parent 3014f23 commit 4fefa2c

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

src/libcore/hint.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ use crate::intrinsics;
4545
/// ```
4646
#[inline]
4747
#[stable(feature = "unreachable", since = "1.27.0")]
48-
pub unsafe fn unreachable_unchecked() -> ! {
48+
#[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")]
49+
pub const unsafe fn unreachable_unchecked() -> ! {
4950
// SAFETY: the safety contract for `intrinsics::unreachable` must
5051
// be upheld by the caller.
5152
unsafe { intrinsics::unreachable() }

src/libcore/intrinsics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ extern "rust-intrinsic" {
932932
///
933933
/// The stabilized version of this intrinsic is
934934
/// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html).
935+
#[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")]
935936
pub fn unreachable() -> !;
936937

937938
/// Informs the optimizer that a condition is always true.

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
#![feature(const_slice_ptr_len)]
9292
#![feature(const_type_name)]
9393
#![feature(const_likely)]
94+
#![feature(const_unreachable_unchecked)]
9495
#![feature(custom_inner_attributes)]
9596
#![feature(decl_macro)]
9697
#![feature(doc_cfg)]

src/librustc_mir/interpret/intrinsics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9595
let (dest, ret) = match ret {
9696
None => match intrinsic_name {
9797
sym::transmute => throw_ub_format!("transmuting to uninhabited type"),
98+
sym::unreachable => throw_ub!(Unreachable),
9899
sym::abort => M::abort(self)?,
99100
// Unsupported diverging intrinsic.
100101
_ => return Ok(false),

0 commit comments

Comments
 (0)