diff --git a/Cargo.toml b/Cargo.toml index f2bef65..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" @@ -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 {