Skip to content

DynMetadata equality is not documented #99388

Closed
@alercah

Description

@alercah
Contributor

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

added
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
on Jul 17, 2022
SimonSapin

SimonSapin commented on Jul 17, 2022

@SimonSapin
Contributor

Vtables are likely not unique at the moment. Yes, documenting that explicitly sounds good. Related: #69757

nbdd0121

nbdd0121 commented on Jul 19, 2022

@nbdd0121
Contributor

Is it necessary to have PartialEq implementaton on DynMetadata?

SimonSapin

SimonSapin commented on Jul 19, 2022

@SimonSapin
Contributor

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 need DynMetadata: PartialEq. This is currently reflected in Pointee::Metadata having a PartialEq 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

RalfJung commented on Jul 22, 2022

@RalfJung
Member

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.

added a commit that references this issue on Feb 11, 2024

Rollup merge of rust-lang#120880 - RalfJung:vtable-fnptr-partialeq, r…

3d7d709
added a commit that references this issue on Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @SimonSapin@RalfJung@nbdd0121@alercah

      Issue actions

        DynMetadata equality is not documented · Issue #99388 · rust-lang/rust