diff --git a/crates/polars-arrow/src/storage.rs b/crates/polars-arrow/src/storage.rs index 864e4dc29d38..7cab3235b25a 100644 --- a/crates/polars-arrow/src/storage.rs +++ b/crates/polars-arrow/src/storage.rs @@ -1,3 +1,4 @@ +use std::marker::PhantomData; use std::mem::ManuallyDrop; use std::ops::Deref; use std::ptr::NonNull; @@ -19,6 +20,8 @@ struct SharedStorageInner { ptr: *mut T, length: usize, backing: Option, + // https://github.com/rust-lang/rfcs/blob/master/text/0769-sound-generic-drop.md#phantom-data + phantom: PhantomData, } impl Drop for SharedStorageInner { @@ -37,6 +40,7 @@ impl Drop for SharedStorageInner { pub struct SharedStorage { inner: NonNull>, + phantom: PhantomData>, } unsafe impl Send for SharedStorage {} @@ -51,9 +55,11 @@ impl SharedStorage { ptr, length, backing: None, + phantom: PhantomData, }; Self { inner: NonNull::new(Box::into_raw(Box::new(inner))).unwrap(), + phantom: PhantomData, } } @@ -67,9 +73,11 @@ impl SharedStorage { ptr, length, backing: Some(BackingStorage::Vec { capacity }), + phantom: PhantomData, }; Self { inner: NonNull::new(Box::into_raw(Box::new(inner))).unwrap(), + phantom: PhantomData, } } @@ -79,9 +87,11 @@ impl SharedStorage { ptr: ptr.cast_mut(), length: len, backing: Some(BackingStorage::InternalArrowArray(arr)), + phantom: PhantomData, }; Self { inner: NonNull::new(Box::into_raw(Box::new(inner))).unwrap(), + phantom: PhantomData, } } } @@ -99,9 +109,11 @@ impl SharedStorage { ptr: ptr as *mut T, length, backing: Some(BackingStorage::ArrowBuffer(buffer)), + phantom: PhantomData, }; Self { inner: NonNull::new(Box::into_raw(Box::new(inner))).unwrap(), + phantom: PhantomData, } } @@ -193,7 +205,10 @@ impl Clone for SharedStorage { // Ordering semantics copied from Arc. inner.ref_count.fetch_add(1, Ordering::Relaxed); } - Self { inner: self.inner } + Self { + inner: self.inner, + phantom: PhantomData, + } } }