diff --git a/crates/bevy_ecs/src/storage/blob_vec.rs b/crates/bevy_ecs/src/storage/blob_vec.rs index c2902553e7124..7b5d8fd80113d 100644 --- a/crates/bevy_ecs/src/storage/blob_vec.rs +++ b/crates/bevy_ecs/src/storage/blob_vec.rs @@ -212,7 +212,7 @@ impl BlobVec { #[inline] pub unsafe fn get_unchecked(&self, index: usize) -> Ptr<'_> { debug_assert!(index < self.len()); - self.get_ptr().add(index * self.item_layout.size()) + self.get_ptr().byte_add(index * self.item_layout.size()) } /// # Safety @@ -221,7 +221,7 @@ impl BlobVec { pub unsafe fn get_unchecked_mut(&mut self, index: usize) -> PtrMut<'_> { debug_assert!(index < self.len()); let layout_size = self.item_layout.size(); - self.get_ptr_mut().add(index * layout_size) + self.get_ptr_mut().byte_add(index * layout_size) } /// Gets a [`Ptr`] to the start of the vec @@ -258,7 +258,7 @@ impl BlobVec { unsafe { // NOTE: this doesn't use self.get_unchecked(i) because the debug_assert on index // will panic here due to self.len being set to 0 - let ptr = self.get_ptr_mut().add(i * layout_size).promote(); + let ptr = self.get_ptr_mut().byte_add(i * layout_size).promote(); (drop)(ptr); } } diff --git a/crates/bevy_ptr/src/lib.rs b/crates/bevy_ptr/src/lib.rs index cb3cc2abb3c39..d590d0bfb1552 100644 --- a/crates/bevy_ptr/src/lib.rs +++ b/crates/bevy_ptr/src/lib.rs @@ -55,7 +55,7 @@ macro_rules! impl_ptr { /// /// [ptr_offset]: https://doc.rust-lang.org/std/primitive.pointer.html#method.offset #[inline] - pub unsafe fn offset(self, count: isize) -> Self { + pub unsafe fn byte_offset(self, count: isize) -> Self { Self( NonNull::new_unchecked(self.as_ptr().offset(count)), PhantomData, @@ -73,7 +73,7 @@ macro_rules! impl_ptr { /// /// [ptr_add]: https://doc.rust-lang.org/std/primitive.pointer.html#method.add #[inline] - pub unsafe fn add(self, count: usize) -> Self { + pub unsafe fn byte_add(self, count: usize) -> Self { Self( NonNull::new_unchecked(self.as_ptr().add(count)), PhantomData, @@ -116,13 +116,9 @@ impl<'a> Ptr<'a> { /// /// If possible, it is strongly encouraged to use [`deref`](Self::deref) over this function, /// as it retains the lifetime. - /// - /// # Safety - /// All subsequent operations to the returned pointer must be valid inside the - /// associated lifetime. #[inline] #[allow(clippy::wrong_self_convention)] - pub unsafe fn as_ptr(self) -> *mut u8 { + pub fn as_ptr(self) -> *mut u8 { self.0.as_ptr() } } @@ -150,13 +146,9 @@ impl<'a> PtrMut<'a> { /// /// If possible, it is strongly encouraged to use [`deref_mut`](Self::deref_mut) over /// this function, as it retains the lifetime. - /// - /// # Safety - /// All subsequent operations to the returned pointer must be valid inside the - /// associated lifetime. #[inline] #[allow(clippy::wrong_self_convention)] - pub unsafe fn as_ptr(self) -> *mut u8 { + pub fn as_ptr(&self) -> *mut u8 { self.0.as_ptr() } } @@ -192,13 +184,9 @@ impl<'a> OwningPtr<'a> { /// /// If possible, it is strongly encouraged to use the other more type-safe functions /// over this function. - /// - /// # Safety - /// All subsequent operations to the returned pointer must be valid inside the - /// associated lifetime. #[inline] #[allow(clippy::wrong_self_convention)] - pub unsafe fn as_ptr(self) -> *mut u8 { + pub fn as_ptr(&self) -> *mut u8 { self.0.as_ptr() } }