Skip to content

Commit

Permalink
Take substs into account in conservative_is_privately_uninhabited
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Jun 30, 2019
1 parent 0af8e87 commit 962bf69
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1702,22 +1702,21 @@ impl<'tcx> TyS<'tcx> {
/// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
/// size, to account for partial initialisation. See #49298 for details.)
pub fn conservative_is_privately_uninhabited(&self, tcx: TyCtxt<'tcx>) -> bool {
// FIXME(varkor): we can make this less conversative by substituting concrete
// type arguments.
match self.sty {
ty::Never => true,
ty::Adt(def, _) if def.is_union() => {
// For now, `union`s are never considered uninhabited.
false
}
ty::Adt(def, _) => {
ty::Adt(def, substs) => {
// Any ADT is uninhabited if either:
// (a) It has no variants (i.e. an empty `enum`);
// (b) Each of its variants (a single one in the case of a `struct`) has at least
// one uninhabited field.
def.variants.iter().all(|var| {
var.fields.iter().any(|field| {
tcx.type_of(field.did).conservative_is_privately_uninhabited(tcx)
tcx.type_of(field.did).subst(tcx, substs)
.conservative_is_privately_uninhabited(tcx)
})
})
}
Expand Down

0 comments on commit 962bf69

Please sign in to comment.