Fix inhabitedness of non-exhaustive variants.

This commit ensures that non-exhaustive variants are considered
inhabited when used in extern crates.
This commit is contained in:
David Wood 2019-05-04 01:17:26 +01:00
parent 0db087e684
commit 0d034a2e4d
No known key found for this signature in database
GPG key ID: 01760B4F9F53F154
3 changed files with 32 additions and 8 deletions

View file

@ -134,9 +134,14 @@ impl<'a, 'gcx, 'tcx> VariantDef {
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)
}))
}
}
}