Skip to content

Commit adfcb61

Browse files
committed
Auto merge of #106450 - albertlarsan68:fix-arc-ptr-eq, r=Amanieu
Make `{Arc,Rc,Weak}::ptr_eq` ignore pointer metadata FCP completed in rust-lang/rust#103763 (comment) Closes #103763
2 parents b167953 + a00a89f commit adfcb61

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

@@ -2466,8 +2466,8 @@ impl<T: ?Sized> Weak<T> {
24662466
}
24672467

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

alloc/src/sync.rs

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

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

@@ -2254,8 +2254,8 @@ impl<T: ?Sized> Weak<T> {
22542254
}
22552255

22562256
/// Returns `true` if the two `Weak`s point to the same allocation similar to [`ptr::eq`], or if
2257-
/// both don't point to any allocation (because they were created with `Weak::new()`). See [that
2258-
/// function][`ptr::eq`] for caveats when comparing `dyn Trait` pointers.
2257+
/// both don't point to any allocation (because they were created with `Weak::new()`). However,
2258+
/// this function ignores the metadata of `dyn Trait` pointers.
22592259
///
22602260
/// # Notes
22612261
///
@@ -2298,7 +2298,7 @@ impl<T: ?Sized> Weak<T> {
22982298
#[must_use]
22992299
#[stable(feature = "weak_ptr_eq", since = "1.39.0")]
23002300
pub fn ptr_eq(&self, other: &Self) -> bool {
2301-
self.ptr.as_ptr() == other.ptr.as_ptr()
2301+
ptr::eq(self.ptr.as_ptr() as *const (), other.ptr.as_ptr() as *const ())
23022302
}
23032303
}
23042304

0 commit comments

Comments
 (0)