Skip to content

attempted to leave type (enum) uninitialized, which is invalid #73573

Description

@stepancheg

This code worked fine a couple of months ago:

#[derive(Copy, Clone, Debug)]
enum Fruit {
    Apple,
    _Banana,
}

fn foo() -> Fruit {
    unsafe {
        let mut r = mem::uninitialized();
        ptr::write(&mut r as *mut Fruit, Fruit::Apple);
        r
    }
}

Now (1.44.1), this code crashes with:

thread 'main' panicked at 'attempted to leave type `Fruit` uninitialized, which is invalid', ...

This code looks perfectly valid to me: we create a slot for a variable, write to that slot exactly once, and return the value.

Play

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

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions