]> git.lizzy.rs Git - rust.git/commitdiff
Put `intrinsics::unreachable` on a possible path to stabilization
authorTobias Bucher <tobiasbucher5991@gmail.com>
Tue, 8 Aug 2017 22:47:38 +0000 (00:47 +0200)
committerTobias Bucher <tobiasbucher5991@gmail.com>
Tue, 8 Aug 2017 22:47:38 +0000 (00:47 +0200)
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.

src/libcore/intrinsics.rs
src/libcore/mem.rs

index 65c18d6d7772b45852b493f57d6c6737083b7b4c..fdca8d00d7a75f1fc0a693765a576b7d536d893d 100644 (file)
     /// 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.
index 866296a5670318c8047ea441e78e89c86256493f..55b34fe81ed5d485634e1f02a8ac06b5ce7e54ab 100644 (file)
@@ -942,3 +942,14 @@ fn fmt(&self, fmt: &mut ::fmt::Formatter) -> ::fmt::Result {
         }
     }
 }
+
+/// 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()
+}