Skip to content

Commit

Permalink
Rollup merge of rust-lang#62261 - varkor:conservative_is_privately_un…
Browse files Browse the repository at this point in the history
…inhabited-subst, r=oli-obk

Take substs into account in `conservative_is_privately_uninhabited`
  • Loading branch information
Centril authored Jul 24, 2019
2 parents 59fb997 + 962bf69 commit c82c77d
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
@@ -1704,22 +1704,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)
})
})
}

0 comments on commit c82c77d

Please sign in to comment.