Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
05storm26 opened this issue May 24, 2021 · 2 comments
Closed

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

05storm26 opened this issue May 24, 2021 · 2 comments
Labels
C-bug Category: This is a bug.

Comments

@05storm26
Copy link

05storm26 commented May 24, 2021

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?

@05storm26 05storm26 added the C-bug Category: This is a bug. label May 24, 2021
@05storm26
Copy link
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,
}

@jyn514
Copy link
Member

jyn514 commented May 24, 2021

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
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants