Skip to content

Commit dde0d8c

Browse files
Deprecate unreachable function
This is designed to merged after #162, as it deprecates a function that should be no longer necessary on newer Rust versions.
1 parent 3ee6d1e commit dde0d8c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: rust
22
rust:
3-
- 1.20.0
3+
- 1.36.0
44
- nightly
55
- beta
66
- stable

lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ use std::borrow::{Borrow, BorrowMut};
5454
use std::cmp;
5555
use std::fmt;
5656
use std::hash::{Hash, Hasher};
57+
use std::hint::unreachable_unchecked;
5758
use std::iter::{IntoIterator, FromIterator, repeat};
5859
use std::mem;
5960
use 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")]
135137
pub 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

Comments
 (0)