Skip to content

Unions with uninhabited variants are considered uninhabited #46845

Description

@gereeter

Uninhabited variants should ideally be irrelevant to the representation, just like in enums.

As a test, this prints out 0 instead of 8:

#![feature(never_type)]
use std::mem;

union Foo {
    a: u64,
    b: !
}

fn main() {
    println!("{}", mem::size_of::<Foo>());
}

This happens because rustc considers unions more like structs than enums, and the test for uninhabitedness sees a single variant with two fields, one of which is uninhabited.

I have a fix for this, but it's slightly easier to bundle it with some other changes I'm working on.

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions