Skip to content

Commit 28feb4c

Browse files
committed
Compare only the data part of fat pointers
Two fat pointers may point to the same data, but with different vtables (the compiler do not guarantee that vtables are unique). Such pointers should be considered equal by std::ptr::eq(), so cast them to thin pointers to compare only their data part. See <rust-lang#48795>.
1 parent 4cdbac6 commit 28feb4c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/libcore/ptr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,8 @@ impl<T: ?Sized> Eq for *mut T {}
21052105
#[stable(feature = "ptr_eq", since = "1.17.0")]
21062106
#[inline]
21072107
pub fn eq<T: ?Sized>(a: *const T, b: *const T) -> bool {
2108-
a == b
2108+
// cast to thin pointers to ignore the vtable part
2109+
a as *const () == b as *const ()
21092110
}
21102111

21112112
// Impls for function pointers

0 commit comments

Comments
 (0)