@@ -57,6 +57,7 @@ use std::borrow::{Borrow, BorrowMut};
57
57
use std:: cmp;
58
58
use std:: fmt;
59
59
use std:: hash:: { Hash , Hasher } ;
60
+ use std:: hint:: unreachable_unchecked;
60
61
#[ cfg( feature = "std" ) ]
61
62
use std:: io;
62
63
use std:: iter:: { repeat, FromIterator , IntoIterator } ;
@@ -129,12 +130,11 @@ macro_rules! smallvec {
129
130
/// Hint to the optimizer that any code path which calls this function is
130
131
/// statically unreachable and can be removed.
131
132
///
132
- /// Equivalent to `std::hint::unreachable_unchecked` but works in older versions of Rust .
133
+ /// Equivalent to `std::hint::unreachable_unchecked`.
133
134
#[ inline]
135
+ #[ deprecated( note = "Use std::hint::unreachable_unchecked instead" ) ]
134
136
pub unsafe fn unreachable ( ) -> ! {
135
- enum Void { }
136
- let x: & Void = mem:: transmute ( 1usize ) ;
137
- match * x { }
137
+ unreachable_unchecked ( )
138
138
}
139
139
140
140
/// `panic!()` in debug builds, optimization hint in release.
@@ -145,7 +145,7 @@ macro_rules! debug_unreachable {
145
145
} ;
146
146
( $e: expr) => {
147
147
if cfg!( not( debug_assertions) ) {
148
- unreachable ( ) ;
148
+ unreachable_unchecked ( ) ;
149
149
} else {
150
150
panic!( $e) ;
151
151
}
@@ -780,7 +780,8 @@ impl<A: Array> SmallVec<A> {
780
780
pub fn swap_remove ( & mut self , index : usize ) -> A :: Item {
781
781
let len = self . len ( ) ;
782
782
self . swap ( len - 1 , index) ;
783
- self . pop ( ) . unwrap_or_else ( || unsafe { unreachable ( ) } )
783
+ self . pop ( )
784
+ . unwrap_or_else ( || unsafe { unreachable_unchecked ( ) } )
784
785
}
785
786
786
787
/// Remove all elements from the vector.
0 commit comments