Skip to content

Did the layout of the trait object metadata change? #85648

Description

@05storm26

I tried this code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=a122541641e9a77365b11b861971d578

According to previous information the first usize pointed by the trait object's metadata/vtable is the size of the struct. This is reiterated in the documentation of the https://doc.rust-lang.org/beta/std/ptr/struct.DynMetadata.html. Did the layout of trait object metadata change?

I expected to see this happen: see the struct's size as the first usize pointed by the trait object's metadata pointer.

Instead, this happened: junk value printed, the second usize appears to be the size of the struct and the third is the alignment.

Is this related to the deprecation of std::raw::TraitObject/#84207?

Activity

  1. 05storm26 commented on May 24, 2021

    @05storm26
    Author

    No it did not change I remembered it wrong the first usize is drop implementation:

    /// The common prefix of all vtables. It is followed by function pointers for trait methods.
    ///
    /// Private implementation detail of `DynMetadata::size_of` etc.
    #[repr(C)]
    struct VTable {
        drop_in_place: fn(*mut ()),
        size_of: usize,
        align_of: usize,
    }
    
  2. jyn514 commented on May 24, 2021

    @jyn514
    Member

    Layout is never guaranteed, and nightly items especially are always subject to change.

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

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions