diff --git a/src/lib.rs b/src/lib.rs index af72fc5..390cd9a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -151,6 +151,7 @@ #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(feature = "unstable", feature(trusted_len))] +#![cfg_attr(feature = "unstable", feature(dropck_eyepatch))] #![allow(clippy::comparison_chain, clippy::missing_safety_doc)] extern crate alloc; @@ -1920,23 +1921,34 @@ impl ThinVec { } } +#[cold] +#[inline(never)] +fn drop_non_singleton(this: &mut ThinVec) { + unsafe { + ptr::drop_in_place(&mut this[..]); + + if this.uses_stack_allocated_buffer() { + return; + } + + dealloc(this.ptr() as *mut u8, layout::(this.capacity())) + } +} + +#[cfg(not(feature = "unstable"))] impl Drop for ThinVec { #[inline] fn drop(&mut self) { - #[cold] - #[inline(never)] - fn drop_non_singleton(this: &mut ThinVec) { - unsafe { - ptr::drop_in_place(&mut this[..]); - - if this.uses_stack_allocated_buffer() { - return; - } - - dealloc(this.ptr() as *mut u8, layout::(this.capacity())) - } + if !self.is_singleton() { + drop_non_singleton(self); } + } +} +#[cfg(feature = "unstable")] +unsafe impl<#[may_dangle] T> Drop for ThinVec { + #[inline] + fn drop(&mut self) { if !self.is_singleton() { drop_non_singleton(self); }