From 77fd7bf7cebeff44d3ea941cf062a3654c0bd959 Mon Sep 17 00:00:00 2001 From: Joseph <21144246+JoJoJet@users.noreply.github.com> Date: Wed, 15 Jan 2025 19:25:19 -0800 Subject: [PATCH] Update safety docs for `Ptr::assert_unique` (#17394) # Objective The safety documentation for `Ptr::assert_unique` is incomplete. Currently it only mentions the existence of other `Ptr` instances, but it should also mention that the underlying data must be mutable and that there cannot be active references to it. --- crates/bevy_ptr/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ptr/src/lib.rs b/crates/bevy_ptr/src/lib.rs index d767a25d4c..adb72409f9 100644 --- a/crates/bevy_ptr/src/lib.rs +++ b/crates/bevy_ptr/src/lib.rs @@ -289,7 +289,9 @@ impl<'a, A: IsAligned> Ptr<'a, A> { /// Transforms this [`Ptr`] into an [`PtrMut`] /// /// # Safety - /// Another [`PtrMut`] for the same [`Ptr`] must not be created until the first is dropped. + /// * The data pointed to by this `Ptr` must be valid for writes. + /// * There must be no active references (mutable or otherwise) to the data underlying this `Ptr`. + /// * Another [`PtrMut`] for the same [`Ptr`] must not be created until the first is dropped. #[inline] pub unsafe fn assert_unique(self) -> PtrMut<'a, A> { PtrMut(self.0, PhantomData)