@@ -54,6 +54,7 @@ use std::borrow::{Borrow, BorrowMut};
5454use std:: cmp;
5555use std:: fmt;
5656use std:: hash:: { Hash , Hasher } ;
57+ use std:: hint:: unreachable_unchecked;
5758use std:: iter:: { IntoIterator , FromIterator , repeat} ;
5859use std:: mem;
5960use std:: mem:: ManuallyDrop ;
@@ -130,12 +131,11 @@ macro_rules! smallvec {
130131/// Hint to the optimizer that any code path which calls this function is
131132/// statically unreachable and can be removed.
132133///
133- /// Equivalent to `std::hint::unreachable_unchecked` but works in older versions of Rust .
134+ /// Equivalent to `std::hint::unreachable_unchecked`.
134135#[ inline]
136+ #[ deprecated( note = "Use std::hint::unreachable_unchecked instead" ) ]
135137pub unsafe fn unreachable ( ) -> ! {
136- enum Void { }
137- let x: & Void = mem:: transmute ( 1usize ) ;
138- match * x { }
138+ unreachable_unchecked ( )
139139}
140140
141141/// `panic!()` in debug builds, optimization hint in release.
@@ -144,7 +144,7 @@ macro_rules! debug_unreachable {
144144 ( ) => { debug_unreachable!( "entered unreachable code" ) } ;
145145 ( $e: expr) => {
146146 if cfg!( not( debug_assertions) ) {
147- unreachable ( ) ;
147+ unreachable_unchecked ( ) ;
148148 } else {
149149 panic!( $e) ;
150150 }
@@ -768,7 +768,7 @@ impl<A: Array> SmallVec<A> {
768768 pub fn swap_remove ( & mut self , index : usize ) -> A :: Item {
769769 let len = self . len ( ) ;
770770 self . swap ( len - 1 , index) ;
771- self . pop ( ) . unwrap_or_else ( || unsafe { unreachable ( ) } )
771+ self . pop ( ) . unwrap_or_else ( || unsafe { unreachable_unchecked ( ) } )
772772 }
773773
774774 /// Remove all elements from the vector.
0 commit comments