This is why I've proposed to make Inhabited
check compiler error only for post-2018 edition, and implement it as a warning in 2018 edition. With auto-trait bound code without UB will not have any problems migrating. Yes, arguably it's a bit too much magic to liking of some, but I think lack of Inhabited
trait will be more harmful in a long run considering Rust safety priorities.
This is exactly why you want Inhabited
bound, to be able to reason if cast is safe or not by knowing that type will always be Inhabited. As for unions, if you will not allow ?Inhabited
on unions, you will not have the problem, as you will not be able to construct union with uninhabited variant. Of course we have unfixable (?) hole with extern fn
which returns !
, but IMO one rare hole is better than 5 common ones.
Inhabited
, as I see it, is not only and so much about catching transmute
misuses, but about an ability to properly encode invariants on type-system level.