From 2511b81e9307c98bd1ed2ed1b29ebf766aca290b Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Sat, 16 Feb 2019 08:00:17 -0800 Subject: [PATCH 1/2] Remove dependency on unmaintained 'unreachable' Fixes #128 by inlining the tiny amount of code we use from `unreachable` and its dependency `void`. Eventually this can be replaced with `std::hint::unrechable_unchecked` but this will require bumping our minumum supported Rust version. This will prevent build breakage from users building with broken versions of the `void` crate, as in crossbeam-rs/crossbeam#312. --- Cargo.toml | 1 - lib.rs | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c0e105c..c9d58bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ name = "smallvec" path = "lib.rs" [dependencies] -unreachable = "1.0.0" serde = { version = "1", optional = true } [dev_dependencies] diff --git a/lib.rs b/lib.rs index 09f925f..4b869e0 100644 --- a/lib.rs +++ b/lib.rs @@ -46,9 +46,6 @@ use alloc::vec::Vec; #[cfg(feature = "serde")] extern crate serde; -extern crate unreachable; -use unreachable::UncheckedOptionExt; - #[cfg(not(feature = "std"))] mod std { pub use core::*; @@ -131,13 +128,24 @@ macro_rules! smallvec { }); } +/// Hint to the optimizer that any code path which calls this function is +/// statically unreachable and can be removed. +/// +/// Equivalent to `std::hint::unreachable_unchecked` but works in older versions of Rust. +#[inline] +pub unsafe fn unreachable() -> ! { + enum Void {} + let x: &Void = mem::transmute(1usize); + match *x {} +} + /// `panic!()` in debug builds, optimization hint in release. #[cfg(not(feature = "union"))] macro_rules! debug_unreachable { () => { debug_unreachable!("entered unreachable code") }; ($e:expr) => { if cfg!(not(debug_assertions)) { - unreachable::unreachable(); + unreachable(); } else { panic!($e); } @@ -758,7 +766,7 @@ impl SmallVec { pub fn swap_remove(&mut self, index: usize) -> A::Item { let len = self.len(); self.swap(len - 1, index); - unsafe { self.pop().unchecked_unwrap() } + self.pop().unwrap_or_else(|| unsafe { unreachable() }) } /// Remove all elements from the vector. From 6510c426157ed8739a7757fa1cc16401a28d66a2 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Sat, 16 Feb 2019 08:04:33 -0800 Subject: [PATCH 2/2] Version 0.6.9 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c9d58bb..cac27aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "smallvec" -version = "0.6.8" +version = "0.6.9" authors = ["Simon Sapin "] license = "MIT/Apache-2.0" repository = "https://github.com/servo/rust-smallvec"