Skip to content

Commit a7e0d3a

Browse files
committed
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.
2 parents edd82ee + faadd35 commit a7e0d3a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/libcore/intrinsics.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,12 @@ extern "rust-intrinsic" {
629629
/// Aborts the execution of the process.
630630
pub fn abort() -> !;
631631

632-
/// Tells LLVM that this point in the code is not reachable,
633-
/// enabling further optimizations.
632+
/// Tells LLVM that this point in the code is not reachable, enabling
633+
/// further optimizations.
634634
///
635-
/// NB: This is very different from the `unreachable!()` macro!
635+
/// NB: This is very different from the `unreachable!()` macro: Unlike the
636+
/// macro, which panics when it is executed, it is *undefined behavior* to
637+
/// reach code marked with this function.
636638
pub fn unreachable() -> !;
637639

638640
/// Informs the optimizer that a condition is always true.

src/libcore/mem.rs

+12
Original file line numberDiff line numberDiff line change
@@ -942,3 +942,15 @@ impl<T: ::fmt::Debug> ::fmt::Debug for ManuallyDrop<T> {
942942
}
943943
}
944944
}
945+
946+
/// Tells LLVM that this point in the code is not reachable, enabling further
947+
/// optimizations.
948+
///
949+
/// NB: This is very different from the `unreachable!()` macro: Unlike the
950+
/// macro, which panics when it is executed, it is *undefined behavior* to
951+
/// reach code marked with this function.
952+
#[inline]
953+
#[unstable(feature = "unreachable", issue = "43751")]
954+
pub unsafe fn unreachable() -> ! {
955+
intrinsics::unreachable()
956+
}

0 commit comments

Comments
 (0)