Skip to content

static instance of #[packed] struct makes Rustc fail #9830

Closed
@LeoTestard

Description

@LeoTestard

I am defining a packed struct the following way:

#[packed]
struct Foo
{
    a: u16,
    b: u32
}

fn main()
{
    println(format!("{:u}", std::sys::size_of::<Foo>()));
}

This code outputs "6" as expected.
Now if I try the following statement:

static f: Foo = Foo { a: 0, b: 0 };

Rustc fails with the following message:

{ i16, i32 } zeroinitializer
<{ i16, i32 }> undef
error: internal compiler error: const expr(17: Foo{a: 0, b: 0,}) of type Foo has size 8 instead of 6

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions