about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTobias Bucher <tobiasbucher5991@gmail.com>2017-08-09 00:47:38 +0200
committerTobias Bucher <tobiasbucher5991@gmail.com>2017-08-09 00:47:38 +0200
commit315de9c58f15612ffacac6f264e50f8f57181080 (patch)
treec5030dbf392555b30b2a13991e5c7348bf36252a
parent215e0b10eac17e43f0132971f4e2dd018fc33d43 (diff)
downloadrust-315de9c58f15612ffacac6f264e50f8f57181080.tar.gz
rust-315de9c58f15612ffacac6f264e50f8f57181080.zip
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.
-rw-r--r--src/libcore/intrinsics.rs8
-rw-r--r--src/libcore/mem.rs11
2 files changed, 16 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..55b34fe81ed 100644
--- a/src/libcore/mem.rs
+++ b/src/libcore/mem.rs
@@ -942,3 +942,14 @@ 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.
+#[unstable(feature = "unreachable", issue = "0")]
+pub unsafe fn unreachable() -> ! {
+    intrinsics::unreachable()
+}