From 315de9c58f15612ffacac6f264e50f8f57181080 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Wed, 9 Aug 2017 00:47:38 +0200 Subject: [PATCH 1/3] 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. --- src/libcore/intrinsics.rs | 8 +++++--- src/libcore/mem.rs | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 65c18d6d7772b..fdca8d00d7a75 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 866296a567031..55b34fe81ed5d 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -942,3 +942,14 @@ impl ::fmt::Debug for ManuallyDrop { } } } + +/// 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() +} From 5704b07667fddb415a1df202885f5ffabe386ff2 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Wed, 9 Aug 2017 01:03:50 +0200 Subject: [PATCH 2/3] `mem::unreachable`: Add tracking issue --- src/libcore/mem.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 55b34fe81ed5d..045720b0268a8 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -949,7 +949,7 @@ impl ::fmt::Debug for ManuallyDrop { /// 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")] +#[unstable(feature = "unreachable", issue = "43751")] pub unsafe fn unreachable() -> ! { intrinsics::unreachable() } From faadd35ee5074aa85fa6e2078650b3e6f1fd4662 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Fri, 11 Aug 2017 03:42:36 +0200 Subject: [PATCH 3/3] Add `#[inline]` to `mem::unreachable` --- src/libcore/mem.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 045720b0268a8..6f7adbe1e7a0e 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -949,6 +949,7 @@ impl ::fmt::Debug for ManuallyDrop { /// 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()