Closed
Description
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.