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
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ยง
use rustc_data_structures::fx::FxHashSet;๐use rustc_hir::def::DefKind;๐use rustc_span::bug;๐use rustc_span::def_id::LocalModId;๐use tracing::instrument;๐use tracing::instrument;๐use crate::query::Providers;๐use crate::ty;๐use crate::ty::AdtDef;๐use crate::ty::DefId;๐use crate::ty::Ty;๐use crate::ty::TyCtxt;๐use crate::ty::TypeVisitableExt;๐use crate::ty::TypingEnv;๐use crate::ty::VariantDef;๐use crate::ty::Visibility;๐pub use inhabited_predicate::InhabitedPredicate;use rustc_type_ir::TyKind::*;๐
Modulesยง
Structsยง
- Opsem
Inhabited ๐Ctx - Context for computing whether a type is inhabited on the opsem level.
See
is_opsem_inhabitedabove for the spec of what we compute.
Functionsยง
- inhabited_
predicate_ ๐for_ def - Returns an
InhabitedPredicatethat is generic over type parameters and requires callingInhabitedPredicate::instantiate - inhabited_
predicate_ ๐type - N.B. this query should only be called through
Ty::inhabited_predicate - is_
opsem_ ๐inhabited_ adt_ cached - provide ๐
- variant_
inhabited_ ๐predicate