From 28feb4c7affabe0a58bf73a150fb74828bf725a2 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 7 Mar 2018 10:03:06 +0100 Subject: [PATCH] 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 . --- src/libcore/ptr.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 6270e5892b3a0..6ed168b3f1761 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2105,7 +2105,8 @@ impl Eq for *mut T {} #[stable(feature = "ptr_eq", since = "1.17.0")] #[inline] pub fn eq(a: *const T, b: *const T) -> bool { - a == b + // cast to thin pointers to ignore the vtable part + a as *const () == b as *const () } // Impls for function pointers