Skip to content

mem::size_of_val returns wrong value for DSTs with certain field layouts #35815

Closed
@apasel422

Description

@apasel422

On stable, beta, and nightly, the follow code prints 16 followed by 24:

struct Foo<T: ?Sized> {
    a: i64,
    b: bool,
    c: T,
}

fn main() {
    let a = Box::new(Foo {a: 1, b: false, c: 1u32});
    println!("{}", std::mem::size_of_val(&*a));

    let a: Box<Foo<Send>> = a;
    println!("{}", std::mem::size_of_val(&*a));
}

CC #27023

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions