Skip to content

Commit

Permalink
Auto merge of #116367 - scottmcm:more-addr-eq, r=workingjubilee
Browse files Browse the repository at this point in the history
Use `addr_eq` in `{Arc,Rc}::ptr_eq`

Since it's made for stuff like this (see #106447)
  • Loading branch information
bors committed Oct 4, 2023
2 parents 187b813 + f8fc0d7 commit 79f38b7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
#![feature(maybe_uninit_uninit_array_transpose)]
#![feature(pattern)]
#![feature(pointer_byte_offsets)]
#![feature(ptr_addr_eq)]
#![feature(ptr_internals)]
#![feature(ptr_metadata)]
#![feature(ptr_sub_ptr)]
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
/// assert!(!Rc::ptr_eq(&five, &other_five));
/// ```
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())
}
}

Expand Down Expand Up @@ -3146,7 +3146,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
#[must_use]
#[stable(feature = "weak_ptr_eq", since = "1.39.0")]
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())
}
}

Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
#[must_use]
#[stable(feature = "ptr_eq", since = "1.17.0")]
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())
}
}

Expand Down Expand Up @@ -2900,7 +2900,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
#[must_use]
#[stable(feature = "weak_ptr_eq", since = "1.39.0")]
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())
}
}

Expand Down

0 comments on commit 79f38b7

Please sign in to comment.