From 962bf69e073b6349ddcf275443c2a814407cab2f Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 1 Jul 2019 00:52:18 +0100 Subject: [PATCH] Take substs into account in `conservative_is_privately_uninhabited` --- src/librustc/ty/sty.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 8bfbd8b854b03..b787f8e3d076d 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -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) }) }) }