As you can see some users completely unaware about pitfalls associated with uninhabited types and write unsafe code accordingly, so requiring explicit opt-in will be a great fail-safe. Honestly I am more uncomfortable with the current status quo and I believe that MaybeUninit is a fig leaf, the only useful thing about which is ability to decouple uninitialized variable creation, writing into it and “converting” into desired type. And because creation of uninitialized variable and work on it usually tightly coupled I don’t see that much benefit in it. All pitfalls are still here, we just added one small step and hope that it will protect users from uninitialized pitfalls.
Can you elaborate why you and @rkruppe wary about negative trait bounds?
I believe it’s very much inhabited type. (note that it compiles, and segfaults only at runtime) Essentially you’ve just created a recursive reference into heap. I think rule of the thumb here is: if mem::size_of does not return 0 it is inhabited type. (well, if we exclude “pathological types” like (u32, !), which I believe should be forbidden)
As I’ve wrote earlier this proposal is not just and not as much about safety of transmute.
Can you provide a real use-case for such transmute call? Considering that with E=!:
match result { Ok(v) => { .. }, Err(e) => { .. } }
In error branch e will be considered inhabited type?
See explanation earlier, IIUC the provided example has nothing to do with uninhabited types.
@arielb1
As I’ve wrote in the beginning of this post, I don’t think that MaybeUninitialized brings too much to the table, you just shift uninhabited type creation to the moment of flipping union to value variant. All hazard of generic code are still here, you’ve just covered it a bit. Yes, we can move unsafe block around, but dragons are still around the corner!