Skip to content

Commit ecaeb59

Browse files
KamilaBorowskadpc
authored andcommitted
Deprecate unreachable function (servo#164)
This is designed to merged after servo#162, as it deprecates a function that should be no longer necessary on newer Rust versions.
1 parent 78acdfa commit ecaeb59

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use std::borrow::{Borrow, BorrowMut};
5757
use std::cmp;
5858
use std::fmt;
5959
use std::hash::{Hash, Hasher};
60+
use std::hint::unreachable_unchecked;
6061
#[cfg(feature = "std")]
6162
use std::io;
6263
use 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")]
134136
pub 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

Comments
 (0)