@@ -57,6 +57,7 @@ use std::borrow::{Borrow, BorrowMut};
5757use std:: cmp;
5858use std:: fmt;
5959use std:: hash:: { Hash , Hasher } ;
60+ use std:: hint:: unreachable_unchecked;
6061#[ cfg( feature = "std" ) ]
6162use std:: io;
6263use std:: iter:: { repeat, FromIterator , IntoIterator } ;
@@ -129,12 +130,11 @@ macro_rules! smallvec {
129130/// Hint to the optimizer that any code path which calls this function is
130131/// statically unreachable and can be removed.
131132///
132- /// Equivalent to `std::hint::unreachable_unchecked` but works in older versions of Rust .
133+ /// Equivalent to `std::hint::unreachable_unchecked`.
133134#[ inline]
135+ #[ deprecated( note = "Use std::hint::unreachable_unchecked instead" ) ]
134136pub unsafe fn unreachable ( ) -> ! {
135- enum Void { }
136- let x: & Void = mem:: transmute ( 1usize ) ;
137- match * x { }
137+ unreachable_unchecked ( )
138138}
139139
140140/// `panic!()` in debug builds, optimization hint in release.
@@ -145,7 +145,7 @@ macro_rules! debug_unreachable {
145145 } ;
146146 ( $e: expr) => {
147147 if cfg!( not( debug_assertions) ) {
148- unreachable ( ) ;
148+ unreachable_unchecked ( ) ;
149149 } else {
150150 panic!( $e) ;
151151 }
@@ -780,7 +780,8 @@ impl<A: Array> SmallVec<A> {
780780 pub fn swap_remove ( & mut self , index : usize ) -> A :: Item {
781781 let len = self . len ( ) ;
782782 self . swap ( len - 1 , index) ;
783- self . pop ( ) . unwrap_or_else ( || unsafe { unreachable ( ) } )
783+ self . pop ( )
784+ . unwrap_or_else ( || unsafe { unreachable_unchecked ( ) } )
784785 }
785786
786787 /// Remove all elements from the vector.
0 commit comments