Skip to content

DynMetadata equality is not documented #99388

Description

@alercah

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

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

    @SimonSapin
    Contributor

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

  3. nbdd0121 commented on Jul 19, 2022

    @nbdd0121
    Member

    Is it necessary to have PartialEq implementaton on DynMetadata?

  4. 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.

  5. 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.

  6. added a commit that references this issue on Feb 11, 2024
  7. 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

      No branches or pull requests

      Issue actions