Skip to content

Commit

Permalink
Put intrinsics::unreachable on a possible path to stabilization
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tbu- committed Aug 8, 2017
1 parent 215e0b1 commit 315de9c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/libcore/intrinsics.rs
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions src/libcore/mem.rs
Expand Up @@ -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()
}

0 comments on commit 315de9c

Please sign in to comment.