From 2fa60c5359a985d0a4dcd2dbefa8f9d3ddc8038a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 21 Nov 2018 11:15:39 +1100 Subject: [PATCH 1/2] Add a new feature, `may_dangle`. This commit adds a `may_dangle` annotation to `drop`, matching `Vec`. This feature increases the ability of `SmallVec` to be used as a drop-in replacement for `Vec`. A feature is necessary because `may_dangle` is Nightly-only. Fixes #132. --- Cargo.toml | 1 + lib.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index f2bef65..86fb21b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ std = [] union = [] default = ["std"] specialization = [] +may_dangle = [] [lib] name = "smallvec" diff --git a/lib.rs b/lib.rs index d3699c0..74c4abf 100644 --- a/lib.rs +++ b/lib.rs @@ -32,6 +32,7 @@ #![cfg_attr(not(feature = "std"), feature(alloc))] #![cfg_attr(feature = "union", feature(untagged_unions))] #![cfg_attr(feature = "specialization", feature(specialization))] +#![cfg_attr(feature = "may_dangle", feature(dropck_eyepatch))] #![deny(missing_docs)] @@ -1374,6 +1375,21 @@ impl Default for SmallVec { } } +#[cfg(feature = "may_dangle")] +unsafe impl<#[may_dangle] A: Array> Drop for SmallVec { + fn drop(&mut self) { + unsafe { + if self.spilled() { + let (ptr, len) = self.data.heap(); + Vec::from_raw_parts(ptr, len, self.capacity); + } else { + ptr::drop_in_place(&mut self[..]); + } + } + } +} + +#[cfg(not(feature = "may_dangle"))] impl Drop for SmallVec { fn drop(&mut self) { unsafe { From 72a500f6739cdf3596e96e128580e050b2350f55 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 30 Nov 2018 08:36:14 +1100 Subject: [PATCH 2/2] Bump version number to 0.6.7. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 86fb21b..1df6384 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "smallvec" -version = "0.6.6" +version = "0.6.7" authors = ["Simon Sapin "] license = "MIT/Apache-2.0" repository = "https://github.com/servo/rust-smallvec"