diff --git a/.travis.yml b/.travis.yml index ee744e1..2dc4702 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: rust rust: - - 1.20.0 + - 1.36.0 - nightly - beta - stable diff --git a/lib.rs b/lib.rs index cedf2bd..2455dde 100644 --- a/lib.rs +++ b/lib.rs @@ -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; @@ -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")] pub unsafe fn unreachable() -> ! { - enum Void {} - let x: &Void = mem::transmute(1usize); - match *x {} + unreachable_unchecked() } /// `panic!()` in debug builds, optimization hint in release. @@ -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); } @@ -768,7 +768,7 @@ impl SmallVec { 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.