Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate unreachable function #164

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: rust
rust:
- 1.20.0
- 1.36.0
- nightly
- beta
- stable
Expand Down
12 changes: 6 additions & 6 deletions lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use std::borrow::{Borrow, BorrowMut};
use std::cmp;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::hint::unreachable_unchecked;
use std::iter::{IntoIterator, FromIterator, repeat};
use std::mem;
use std::mem::ManuallyDrop;
Expand Down Expand Up @@ -130,12 +131,11 @@ macro_rules! smallvec {
/// Hint to the optimizer that any code path which calls this function is
/// statically unreachable and can be removed.
///
/// Equivalent to `std::hint::unreachable_unchecked` but works in older versions of Rust.
/// Equivalent to `std::hint::unreachable_unchecked`.
#[inline]
#[deprecated(note = "Use std::hint::unreachable_unchecked instead")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given we're going to do a breaking version change, I'd rather just remove it.

pub unsafe fn unreachable() -> ! {
enum Void {}
let x: &Void = mem::transmute(1usize);
match *x {}
unreachable_unchecked()
}

/// `panic!()` in debug builds, optimization hint in release.
Expand All @@ -144,7 +144,7 @@ macro_rules! debug_unreachable {
() => { debug_unreachable!("entered unreachable code") };
($e:expr) => {
if cfg!(not(debug_assertions)) {
unreachable();
unreachable_unchecked();
} else {
panic!($e);
}
Expand Down Expand Up @@ -768,7 +768,7 @@ impl<A: Array> SmallVec<A> {
pub fn swap_remove(&mut self, index: usize) -> A::Item {
let len = self.len();
self.swap(len - 1, index);
self.pop().unwrap_or_else(|| unsafe { unreachable() })
self.pop().unwrap_or_else(|| unsafe { unreachable_unchecked() })
}

/// Remove all elements from the vector.
Expand Down