Skip to content

Commit 21e9227

Browse files
Make {Arc,Rc,Weak}::ptr_eq ignore pointer metadata
1 parent 7f6ae09 commit 21e9227

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

alloc/src/rc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ impl<T: ?Sized> Rc<T> {
11691169
#[inline]
11701170
#[stable(feature = "ptr_eq", since = "1.17.0")]
11711171
/// Returns `true` if the two `Rc`s point to the same allocation in a vein similar to
1172-
/// [`ptr::eq`]. See [that function][`ptr::eq`] for caveats when comparing `dyn Trait` pointers.
1172+
/// [`ptr::eq`]. This function ignores the metadata of `dyn Trait` pointers.
11731173
///
11741174
/// # Examples
11751175
///
@@ -1184,7 +1184,7 @@ impl<T: ?Sized> Rc<T> {
11841184
/// assert!(!Rc::ptr_eq(&five, &other_five));
11851185
/// ```
11861186
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
1187-
this.ptr.as_ptr() == other.ptr.as_ptr()
1187+
this.ptr.as_ptr() as *const () == other.ptr.as_ptr() as *const ()
11881188
}
11891189
}
11901190

@@ -2468,8 +2468,8 @@ impl<T: ?Sized> Weak<T> {
24682468
}
24692469

24702470
/// Returns `true` if the two `Weak`s point to the same allocation similar to [`ptr::eq`], or if
2471-
/// both don't point to any allocation (because they were created with `Weak::new()`). See [that
2472-
/// function][`ptr::eq`] for caveats when comparing `dyn Trait` pointers.
2471+
/// both don't point to any allocation (because they were created with `Weak::new()`). However,
2472+
/// this function ignores the metadata of `dyn Trait` pointers.
24732473
///
24742474
/// # Notes
24752475
///
@@ -2510,7 +2510,7 @@ impl<T: ?Sized> Weak<T> {
25102510
#[must_use]
25112511
#[stable(feature = "weak_ptr_eq", since = "1.39.0")]
25122512
pub fn ptr_eq(&self, other: &Self) -> bool {
2513-
self.ptr.as_ptr() == other.ptr.as_ptr()
2513+
ptr::eq(self.ptr.as_ptr() as *const (), other.ptr.as_ptr() as *const ())
25142514
}
25152515
}
25162516

alloc/src/sync.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ impl<T: ?Sized> Arc<T> {
12631263
}
12641264

12651265
/// Returns `true` if the two `Arc`s point to the same allocation in a vein similar to
1266-
/// [`ptr::eq`]. See [that function][`ptr::eq`] for caveats when comparing `dyn Trait` pointers.
1266+
/// [`ptr::eq`]. This function ignores the metadata of `dyn Trait` pointers.
12671267
///
12681268
/// # Examples
12691269
///
@@ -1283,7 +1283,7 @@ impl<T: ?Sized> Arc<T> {
12831283
#[must_use]
12841284
#[stable(feature = "ptr_eq", since = "1.17.0")]
12851285
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
1286-
this.ptr.as_ptr() == other.ptr.as_ptr()
1286+
this.ptr.as_ptr() as *const () == other.ptr.as_ptr() as *const ()
12871287
}
12881288
}
12891289

@@ -2243,8 +2243,8 @@ impl<T: ?Sized> Weak<T> {
22432243
}
22442244

22452245
/// Returns `true` if the two `Weak`s point to the same allocation similar to [`ptr::eq`], or if
2246-
/// both don't point to any allocation (because they were created with `Weak::new()`). See [that
2247-
/// function][`ptr::eq`] for caveats when comparing `dyn Trait` pointers.
2246+
/// both don't point to any allocation (because they were created with `Weak::new()`). However,
2247+
/// this function ignores the metadata of `dyn Trait` pointers.
22482248
///
22492249
/// # Notes
22502250
///
@@ -2287,7 +2287,7 @@ impl<T: ?Sized> Weak<T> {
22872287
#[must_use]
22882288
#[stable(feature = "weak_ptr_eq", since = "1.39.0")]
22892289
pub fn ptr_eq(&self, other: &Self) -> bool {
2290-
self.ptr.as_ptr() == other.ptr.as_ptr()
2290+
ptr::eq(self.ptr.as_ptr() as *const (), other.ptr.as_ptr() as *const ())
22912291
}
22922292
}
22932293

0 commit comments

Comments
 (0)