From: Tobias Bucher Date: Tue, 8 Aug 2017 22:47:38 +0000 (+0200) Subject: Put `intrinsics::unreachable` on a possible path to stabilization X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=315de9c58f15612ffacac6f264e50f8f57181080;p=rust.git 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. --- 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 @@ /// 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 @@ 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() +}