diff --git a/src/macros.rs b/src/macros.rs index f84f868..bde9888 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -6,7 +6,7 @@ macro_rules! debug_unreachable { }; ($e:expr) => { if cfg!(not(debug_assertions)) { - crate::utils::unreachable(); + core::hint::unreachable_unchecked(); } else { panic!($e); } diff --git a/src/small_vec.rs b/src/small_vec.rs index 46f3acc..1dd2248 100644 --- a/src/small_vec.rs +++ b/src/small_vec.rs @@ -2,7 +2,7 @@ use crate::small_vec_visitor::SmallVecVisitor; #[cfg(feature = "specialization")] use crate::spec_from::SpecFrom; -use crate::utils::{deallocate, unreachable}; +use crate::utils::deallocate; #[cfg(not(feature = "const_generics"))] use crate::Array; use crate::{ @@ -13,6 +13,7 @@ use core::{ cmp::{Eq, Ord, Ordering, PartialOrd}, fmt::{self, Debug}, hash::{Hash, Hasher}, + hint::unreachable_unchecked, iter::{repeat, FromIterator}, mem::{self, MaybeUninit}, ops::{Deref, DerefMut, Index, IndexMut, Range, RangeFrom, RangeFull, RangeTo}, @@ -435,7 +436,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. diff --git a/src/utils.rs b/src/utils.rs index fd9c17d..1a765c2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,17 +1,4 @@ -use core::mem; - pub unsafe fn deallocate(ptr: *mut T, capacity: usize) { let _vec: Vec = Vec::from_raw_parts(ptr, 0, capacity); // Let it drop. -} - -/// 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. -#[inline] -pub unsafe fn unreachable() -> ! { - enum Void {} - let x: &Void = mem::transmute(1usize); - match *x {} -} +} \ No newline at end of file