Use addr_eq in {Arc,Rc}::ptr_eq

Since it's made for stuff like this (see 106447)
This commit is contained in:
Scott McMurray 2023-10-02 17:32:01 -07:00
parent 2e5a9dd6c9
commit f8fc0d7716
3 changed files with 5 additions and 4 deletions

View File

@ -140,6 +140,7 @@
#![feature(maybe_uninit_uninit_array_transpose)] #![feature(maybe_uninit_uninit_array_transpose)]
#![feature(pattern)] #![feature(pattern)]
#![feature(pointer_byte_offsets)] #![feature(pointer_byte_offsets)]
#![feature(ptr_addr_eq)]
#![feature(ptr_internals)] #![feature(ptr_internals)]
#![feature(ptr_metadata)] #![feature(ptr_metadata)]
#![feature(ptr_sub_ptr)] #![feature(ptr_sub_ptr)]

View File

@ -1649,7 +1649,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
/// assert!(!Rc::ptr_eq(&five, &other_five)); /// assert!(!Rc::ptr_eq(&five, &other_five));
/// ``` /// ```
pub fn ptr_eq(this: &Self, other: &Self) -> bool { pub fn ptr_eq(this: &Self, other: &Self) -> bool {
this.ptr.as_ptr() as *const () == other.ptr.as_ptr() as *const () ptr::addr_eq(this.ptr.as_ptr(), other.ptr.as_ptr())
} }
} }
@ -3146,7 +3146,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
#[must_use] #[must_use]
#[stable(feature = "weak_ptr_eq", since = "1.39.0")] #[stable(feature = "weak_ptr_eq", since = "1.39.0")]
pub fn ptr_eq(&self, other: &Self) -> bool { pub fn ptr_eq(&self, other: &Self) -> bool {
ptr::eq(self.ptr.as_ptr() as *const (), other.ptr.as_ptr() as *const ()) ptr::addr_eq(self.ptr.as_ptr(), other.ptr.as_ptr())
} }
} }

View File

@ -1778,7 +1778,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
#[must_use] #[must_use]
#[stable(feature = "ptr_eq", since = "1.17.0")] #[stable(feature = "ptr_eq", since = "1.17.0")]
pub fn ptr_eq(this: &Self, other: &Self) -> bool { pub fn ptr_eq(this: &Self, other: &Self) -> bool {
this.ptr.as_ptr() as *const () == other.ptr.as_ptr() as *const () ptr::addr_eq(this.ptr.as_ptr(), other.ptr.as_ptr())
} }
} }
@ -2900,7 +2900,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
#[must_use] #[must_use]
#[stable(feature = "weak_ptr_eq", since = "1.39.0")] #[stable(feature = "weak_ptr_eq", since = "1.39.0")]
pub fn ptr_eq(&self, other: &Self) -> bool { pub fn ptr_eq(&self, other: &Self) -> bool {
ptr::eq(self.ptr.as_ptr() as *const (), other.ptr.as_ptr() as *const ()) ptr::addr_eq(self.ptr.as_ptr(), other.ptr.as_ptr())
} }
} }