about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNazım Can Altınova <canaltinova@gmail.com>2020-07-17 21:57:13 +0200
committerNazım Can Altınova <canaltinova@gmail.com>2020-07-17 21:57:13 +0200
commit4fefa2c75d43dcf1184c7a7116cbd9595a8e49ab (patch)
tree62c35c8ddaacb6b5a6fc2ca60116115cff4f1d8b
parent3014f23ddd437d2ba9947383c4565d09c1eb39f2 (diff)
downloadrust-4fefa2c75d43dcf1184c7a7116cbd9595a8e49ab.tar.gz
rust-4fefa2c75d43dcf1184c7a7116cbd9595a8e49ab.zip
Make unreachable_unchecked a const fn
-rw-r--r--src/libcore/hint.rs3
-rw-r--r--src/libcore/intrinsics.rs1
-rw-r--r--src/libcore/lib.rs1
-rw-r--r--src/librustc_mir/interpret/intrinsics.rs1
4 files changed, 5 insertions, 1 deletions
diff --git a/src/libcore/hint.rs b/src/libcore/hint.rs
index 9ebcde79b63..3116815f5d6 100644
--- a/src/libcore/hint.rs
+++ b/src/libcore/hint.rs
@@ -45,7 +45,8 @@ use crate::intrinsics;
 /// ```
 #[inline]
 #[stable(feature = "unreachable", since = "1.27.0")]
-pub unsafe fn unreachable_unchecked() -> ! {
+#[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")]
+pub const unsafe fn unreachable_unchecked() -> ! {
     // SAFETY: the safety contract for `intrinsics::unreachable` must
     // be upheld by the caller.
     unsafe { intrinsics::unreachable() }
diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs
index 080760aa81f..8f0cf4361e7 100644
--- a/src/libcore/intrinsics.rs
+++ b/src/libcore/intrinsics.rs
@@ -932,6 +932,7 @@ extern "rust-intrinsic" {
     ///
     /// The stabilized version of this intrinsic is
     /// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html).
+    #[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")]
     pub fn unreachable() -> !;
 
     /// Informs the optimizer that a condition is always true.
diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs
index 96436bb253d..a8c9b8f2577 100644
--- a/src/libcore/lib.rs
+++ b/src/libcore/lib.rs
@@ -91,6 +91,7 @@
 #![feature(const_slice_ptr_len)]
 #![feature(const_type_name)]
 #![feature(const_likely)]
+#![feature(const_unreachable_unchecked)]
 #![feature(custom_inner_attributes)]
 #![feature(decl_macro)]
 #![feature(doc_cfg)]
diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs
index 85186264022..5836fc9c95a 100644
--- a/src/librustc_mir/interpret/intrinsics.rs
+++ b/src/librustc_mir/interpret/intrinsics.rs
@@ -95,6 +95,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
         let (dest, ret) = match ret {
             None => match intrinsic_name {
                 sym::transmute => throw_ub_format!("transmuting to uninhabited type"),
+                sym::unreachable => throw_ub!(Unreachable),
                 sym::abort => M::abort(self)?,
                 // Unsupported diverging intrinsic.
                 _ => return Ok(false),