Skip to content

Commit f8fc0d7

Browse files
committed
Use addr_eq in {Arc,Rc}::ptr_eq
Since it's made for stuff like this (see 106447)
1 parent 2e5a9dd commit f8fc0d7

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

library/alloc/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
#![feature(maybe_uninit_uninit_array_transpose)]
141141
#![feature(pattern)]
142142
#![feature(pointer_byte_offsets)]
143+
#![feature(ptr_addr_eq)]
143144
#![feature(ptr_internals)]
144145
#![feature(ptr_metadata)]
145146
#![feature(ptr_sub_ptr)]

library/alloc/src/rc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
16491649
/// assert!(!Rc::ptr_eq(&five, &other_five));
16501650
/// ```
16511651
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
1652-
this.ptr.as_ptr() as *const () == other.ptr.as_ptr() as *const ()
1652+
ptr::addr_eq(this.ptr.as_ptr(), other.ptr.as_ptr())
16531653
}
16541654
}
16551655

@@ -3146,7 +3146,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
31463146
#[must_use]
31473147
#[stable(feature = "weak_ptr_eq", since = "1.39.0")]
31483148
pub fn ptr_eq(&self, other: &Self) -> bool {
3149-
ptr::eq(self.ptr.as_ptr() as *const (), other.ptr.as_ptr() as *const ())
3149+
ptr::addr_eq(self.ptr.as_ptr(), other.ptr.as_ptr())
31503150
}
31513151
}
31523152

library/alloc/src/sync.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
17781778
#[must_use]
17791779
#[stable(feature = "ptr_eq", since = "1.17.0")]
17801780
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
1781-
this.ptr.as_ptr() as *const () == other.ptr.as_ptr() as *const ()
1781+
ptr::addr_eq(this.ptr.as_ptr(), other.ptr.as_ptr())
17821782
}
17831783
}
17841784

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

0 commit comments

Comments
 (0)