diff --git a/src/zeroable.rs b/src/zeroable.rs index ac79152..687ba0f 100644 --- a/src/zeroable.rs +++ b/src/zeroable.rs @@ -53,8 +53,17 @@ unsafe impl Zeroable for f64 {} unsafe impl Zeroable for Wrapping {} unsafe impl Zeroable for core::cmp::Reverse {} +// Note: we can't implement this for all `T: ?Sized` types because it would +// create NULL pointers for vtables. +// Maybe one day this could be changed to be implemented for +// `T: ?Sized where ::Metadata: Zeroable`. unsafe impl Zeroable for *mut T {} unsafe impl Zeroable for *const T {} +unsafe impl Zeroable for *mut [T] {} +unsafe impl Zeroable for *const [T] {} +unsafe impl Zeroable for *mut str {} +unsafe impl Zeroable for *const str {} + unsafe impl Zeroable for PhantomData {} unsafe impl Zeroable for PhantomPinned {} unsafe impl Zeroable for ManuallyDrop {} diff --git a/src/zeroable_in_option.rs b/src/zeroable_in_option.rs index db6c083..b60beb1 100644 --- a/src/zeroable_in_option.rs +++ b/src/zeroable_in_option.rs @@ -25,4 +25,10 @@ unsafe impl ZeroableInOption for NonZeroU64 {} unsafe impl ZeroableInOption for NonZeroU128 {} unsafe impl ZeroableInOption for NonZeroUsize {} -unsafe impl ZeroableInOption for NonNull {} +// Note: this does not create NULL vtable because we get `None` anyway. +unsafe impl ZeroableInOption for NonNull {} +unsafe impl ZeroableInOption for &'_ T {} +unsafe impl ZeroableInOption for &'_ mut T {} + +#[cfg(feature = "extern_crate_alloc")] +unsafe impl ZeroableInOption for alloc::boxed::Box {}