diff options
| author | bors <bors@rust-lang.org> | 2025-03-20 14:31:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-03-20 14:31:34 +0000 |
| commit | d8e44b722a93e55cbc9a8188dfbfe3faf1226096 (patch) | |
| tree | 813918a15fdb2dc6bb9118f328afc4fc5c83b711 /compiler/rustc_middle/src | |
| parent | 87e60a7d285f8ea560189024f85f2b194d1f168f (diff) | |
| parent | 0a6a0e47d2efb207ad0e95c3eb67b543c8cbb2e6 (diff) | |
| download | rust-d8e44b722a93e55cbc9a8188dfbfe3faf1226096.tar.gz rust-d8e44b722a93e55cbc9a8188dfbfe3faf1226096.zip | |
Auto merge of #133889 - compiler-errors:inh-unstable, r=Nadrieril
Consider fields to be inhabited if they are unstable Fixes #133885 with a simple heuristic r? Nadrieril Not totally certain if this needs T-lang approval or a crater run.
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/ty/inhabitedness/mod.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs index 855e5043e84..32988965a35 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs @@ -43,6 +43,7 @@ //! This code should only compile in modules where the uninhabitedness of `Foo` //! is visible. +use rustc_span::sym; use rustc_type_ir::TyKind::*; use tracing::instrument; @@ -84,6 +85,21 @@ 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. + // HACK: We filter out `rustc_private` fields since with the flag + // `-Zforce-unstable-if-unmarked` we consider all unmarked fields to be + // unstable when building the compiler. + if tcx + .lookup_stability(field.did) + .is_some_and(|stab| stab.is_unstable() && stab.feature != sym::rustc_private) + { + return InhabitedPredicate::True; + } let pred = tcx.type_of(field.did).instantiate_identity().inhabited_predicate(tcx); if adt.is_enum() { return pred; |
