about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-08-11 19:43:44 +0000
committerbors <bors@rust-lang.org>2017-08-11 19:43:44 +0000
commita7e0d3a81f224649c8fcfc8ac3cb93f1e1107bea (patch)
treeaede5c10be8e1ee591381c67ddafadfbe5881a4c /src/libcore
parentedd82ee9f09c74188f88440db6586ef8e5b1c0b2 (diff)
parentfaadd35ee5074aa85fa6e2078650b3e6f1fd4662 (diff)
Auto merge of #43750 - tbu-:pr_fn_unreachable, r=sfackler
Put `intrinsics::unreachable` on a possible path to stabilization

Mark it with the `unreachable` feature and put it into the `mem` module.
This is a pretty straight-forward API that can already be simulated in
stable Rust by using `transmute` to create an uninhabited enum that can
be matched.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/intrinsics.rs8
-rw-r--r--src/libcore/mem.rs12
2 files changed, 17 insertions, 3 deletions
diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs
index 65c18d6d777..fdca8d00d7a 100644
--- a/src/libcore/intrinsics.rs
+++ b/src/libcore/intrinsics.rs
@@ -629,10 +629,12 @@ extern "rust-intrinsic" {
     /// Aborts the execution of the process.
     pub fn abort() -> !;
 
-    /// Tells LLVM that this point in the code is not reachable,
-    /// enabling further optimizations.
+    /// Tells LLVM that this point in the code is not reachable, enabling
+    /// further optimizations.
     ///
-    /// NB: This is very different from the `unreachable!()` macro!
+    /// NB: This is very different from the `unreachable!()` macro: Unlike the
+    /// macro, which panics when it is executed, it is *undefined behavior* to
+    /// reach code marked with this function.
     pub fn unreachable() -> !;
 
     /// Informs the optimizer that a condition is always true.
diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs
index 866296a5670..6f7adbe1e7a 100644
--- a/src/libcore/mem.rs
+++ b/src/libcore/mem.rs
@@ -942,3 +942,15 @@ impl<T: ::fmt::Debug> ::fmt::Debug for ManuallyDrop<T> {
         }
     }
 }
+
+/// Tells LLVM that this point in the code is not reachable, enabling further
+/// optimizations.
+///
+/// NB: This is very different from the `unreachable!()` macro: Unlike the
+/// macro, which panics when it is executed, it is *undefined behavior* to
+/// reach code marked with this function.
+#[inline]
+#[unstable(feature = "unreachable", issue = "43751")]
+pub unsafe fn unreachable() -> ! {
+    intrinsics::unreachable()
+}