]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/ty/inhabitedness/mod.rs
Auto merge of #60708 - Centril:rollup-j5smdo0, r=Centril
[rust.git] / src / librustc / ty / inhabitedness / mod.rs
index 197d3325f51cfdb232dd3c8b3815a9788baca0c3..be1d973c2cdd58363b7c15e855daffacb60c0c31 100644 (file)
@@ -113,9 +113,14 @@ fn uninhabited_from(
         tcx: TyCtxt<'a, 'gcx, 'tcx>,
         substs: SubstsRef<'tcx>) -> DefIdForest
     {
-        DefIdForest::intersection(tcx, self.variants.iter().map(|v| {
-            v.uninhabited_from(tcx, substs, self.adt_kind())
-        }))
+        // Non-exhaustive ADTs from other crates are always considered inhabited.
+        if self.is_variant_list_non_exhaustive() && !self.did.is_local() {
+            DefIdForest::empty()
+        } else {
+            DefIdForest::intersection(tcx, self.variants.iter().map(|v| {
+                v.uninhabited_from(tcx, substs, self.adt_kind())
+            }))
+        }
     }
 }
 
@@ -134,9 +139,14 @@ pub fn uninhabited_from(
             AdtKind::Enum => true,
             AdtKind::Struct => false,
         };
-        DefIdForest::union(tcx, self.fields.iter().map(|f| {
-            f.uninhabited_from(tcx, substs, is_enum)
-        }))
+        // Non-exhaustive variants from other crates are always considered inhabited.
+        if self.is_field_list_non_exhaustive() && !self.def_id.is_local() {
+            DefIdForest::empty()
+        } else {
+            DefIdForest::union(tcx, self.fields.iter().map(|f| {
+                f.uninhabited_from(tcx, substs, is_enum)
+            }))
+        }
     }
 }