Blog post: never patterns, exhaustive matching, and uninhabited types

Having finally written that blog post on validity of values, I can now clarify why I think there are multiple notions of “uninhabited”: Some types do not have any valid inhabitants – they are as uninhabited as it gets. Examples are ! or any empty enum, but also (i32, !).

Other types do not have any safe inhabitants, but they might have valid inhabitants. An example of such a type is

struct Recursive<'a>(&'a mut Recursive<'a>);

According to my definition, Recursive(MaybeUninit::<Recursive>::get_mut()) is valid for Recursive but not safe – there is no safe inhabitant.

4 Likes