Expand description
This module contains logic for determining whether a type is inhabited or
uninhabited. The InhabitedPredicate
type captures the minimum
information needed to determine whether a type is inhabited given a
ParamEnv
and module ID.
§Example
#![feature(never_type)]
mod a {
pub mod b {
pub struct SecretlyUninhabited {
_priv: !,
}
}
}
mod c {
enum Void {}
pub struct AlsoSecretlyUninhabited {
_priv: Void,
}
mod d {
}
}
struct Foo {
x: a::b::SecretlyUninhabited,
y: c::AlsoSecretlyUninhabited,
}
In this code, the type Foo
will only be visibly uninhabited inside the
modules b
, c
and d
. Calling inhabited_predicate
on Foo
will
return NotInModule(b) AND NotInModule(c)
.
We need this information for pattern-matching on Foo
or types that contain
Foo
.
§Example
ⓘ
let foo_result: Result<T, Foo> = ... ;
let Ok(t) = foo_result;
This code should only compile in modules where the uninhabitedness of Foo
is visible.
Re-exports§
pub use inhabited_predicate::InhabitedPredicate;
Modules§
Functions§
- Returns an
InhabitedPredicate
that is generic over type parameters and requires callingInhabitedPredicate::instantiate
- N.B. this query should only be called through
Ty::inhabited_predicate
- provide 🔒