Closed
Description
Location
https://doc.rust-lang.org/std/ptr/struct.DynMetadata.html
Summary
There is no documentation as far as I should see that defines the behaviour of the PartialEq
impl for DynMetadata
. I think the guarantees that are made or not made should be documented. For instance, are vtables for a given concrete type guaranteed to be unique? People will assume they are, and that ==
will tell you if the types match. It would not surprise me to learn that this is wrong.
Activity
SimonSapin commentedon Jul 17, 2022
Vtables are likely not unique at the moment. Yes, documenting that explicitly sounds good. Related: #69757
nbdd0121 commentedon Jul 19, 2022
Is it necessary to have
PartialEq
implementaton onDynMetadata
?SimonSapin commentedon Jul 19, 2022
All raw pointers (including to trait objects) implement
PartialEq
, and they conceptually do it by comparing(ptr as *const (), metadata(ptr))
. For that formulation to work, we’d needDynMetadata: PartialEq
. This is currently reflected inPointee::Metadata
having aPartialEq
bound.However the current implementation of raw pointer comparison is just bitwise comparison and does not go through
metadata()
, so it would technically be possible to remove this bound and impl. I’m not sure it’s desirable, though.RalfJung commentedon Jul 22, 2022
One can compare vtable pointers via wide raw pointer comparison, so for better or worse I think we should also allow it on
DynMetadata
. That might be a good place to document the footguns related to comparison of vtables.Rollup merge of rust-lang#120880 - RalfJung:vtable-fnptr-partialeq, r…
Unrolled build for rust-lang#120880