Skip to content

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

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

Closed
LeoTestard opened this issue Oct 12, 2013 · 0 comments · Fixed by #9832
Closed

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

LeoTestard opened this issue Oct 12, 2013 · 0 comments · Fixed by #9832
Labels
A-codegen Area: Code generation

Comments

@LeoTestard
Copy link
Contributor

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
@bors bors closed this as completed in 91abfd4 Oct 13, 2013
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 21, 2022
…arth

Make `bool_to_int_with_if` a pedantic lint

In all the cases I've observed, it did not make the code clearer. Using bools as integer is frowned upon in some languages, in others it's simply not possible.

You can find comments on the original pull request rust-lang#8131 that agree with this point of view.

changelog: [`bool_to_int_with_if`]: Change the categorization to pedantic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant