diff --git a/compiler/rustc_data_structures/src/tagged_ptr/copy.rs b/compiler/rustc_data_structures/src/tagged_ptr/copy.rs index 235c92da699..644f1415e73 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr/copy.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr/copy.rs @@ -115,19 +115,6 @@ pub fn pointer(self) -> P unsafe { P::from_ptr(self.pointer_raw()) } } - pub fn pointer_ref(&self) -> &P::Target { - // SAFETY: pointer_raw returns the original pointer - unsafe { self.pointer_raw().as_ref() } - } - - pub fn pointer_mut(&mut self) -> &mut P::Target - where - P: DerefMut, - { - // SAFETY: pointer_raw returns the original pointer - unsafe { self.pointer_raw().as_mut() } - } - #[inline] pub fn tag(&self) -> T { unsafe { T::from_usize(self.packed.addr().get() >> Self::TAG_BIT_SHIFT) } @@ -147,7 +134,10 @@ impl Deref for CopyTaggedPtr &Self::Target { - self.pointer_ref() + // Safety: + // `pointer_raw` returns the original pointer from `P::into_ptr` which, + // by the `Pointer`'s contract, must be valid. + unsafe { self.pointer_raw().as_ref() } } } @@ -157,7 +147,11 @@ impl DerefMut for CopyTaggedPtr &mut Self::Target { - self.pointer_mut() + // Safety: + // `pointer_raw` returns the original pointer from `P::into_ptr` which, + // by the `Pointer`'s contract, must be valid for writes if + // `P: DerefMut`. + unsafe { self.pointer_raw().as_mut() } } } diff --git a/compiler/rustc_data_structures/src/tagged_ptr/drop.rs b/compiler/rustc_data_structures/src/tagged_ptr/drop.rs index d3fba0c30a9..6e51916838f 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr/drop.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr/drop.rs @@ -41,9 +41,6 @@ pub fn new(pointer: P, tag: T) -> Self { TaggedPtr { raw: CopyTaggedPtr::new(pointer, tag) } } - pub fn pointer_ref(&self) -> &P::Target { - self.raw.pointer_ref() - } pub fn tag(&self) -> T { self.raw.tag() } @@ -56,7 +53,7 @@ impl std::ops::Deref for TaggedPtr &Self::Target { - self.raw.pointer_ref() + self.raw.deref() } } @@ -66,7 +63,7 @@ impl std::ops::DerefMut for TaggedPtr &mut Self::Target { - self.raw.pointer_mut() + self.raw.deref_mut() } }