You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[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.