1
Fork 0

Consider fields to be inhabited if they are unstable

This commit is contained in:
Michael Goulet 2025-03-18 18:23:32 +00:00
parent 75530e9f72
commit f6107ca173
6 changed files with 95 additions and 1 deletions

View file

@ -84,6 +84,15 @@ impl<'tcx> VariantDef {
InhabitedPredicate::all(
tcx,
self.fields.iter().map(|field| {
// Unstable fields are always considered to be inhabited. In the future,
// this could be extended to be conditional on the field being unstable
// only within the module that's querying the inhabitedness, like:
// `let pred = pred.or(InhabitedPredicate::IsUnstable(field.did));`
// but this is unnecessary for now, since it would only affect nightly-only
// code or code within the standard library itself.
if tcx.lookup_stability(field.did).is_some_and(|stab| stab.is_unstable()) {
return InhabitedPredicate::True;
}
let pred = tcx.type_of(field.did).instantiate_identity().inhabited_predicate(tcx);
if adt.is_enum() {
return pred;