Skip to content

Commit aaed1dc

Browse files
committed
Don't consider unstable fields always-inhabited
This reverts the hack in rust-lang#133889 now that `Pin`'s field is no longer public.
1 parent 6dec76f commit aaed1dc

File tree

2 files changed

+2
-21
lines changed
  • compiler
    • rustc_middle/src/ty/inhabitedness
    • rustc_pattern_analysis/src

2 files changed

+2
-21
lines changed

compiler/rustc_middle/src/ty/inhabitedness/mod.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
//! This code should only compile in modules where the uninhabitedness of `Foo`
4444
//! is visible.
4545
46-
use rustc_span::sym;
4746
use rustc_type_ir::TyKind::*;
4847
use tracing::instrument;
4948

@@ -85,21 +84,6 @@ impl<'tcx> VariantDef {
8584
InhabitedPredicate::all(
8685
tcx,
8786
self.fields.iter().map(|field| {
88-
// Unstable fields are always considered to be inhabited. In the future,
89-
// this could be extended to be conditional on the field being unstable
90-
// only within the module that's querying the inhabitedness, like:
91-
// `let pred = pred.or(InhabitedPredicate::IsUnstable(field.did));`
92-
// but this is unnecessary for now, since it would only affect nightly-only
93-
// code or code within the standard library itself.
94-
// HACK: We filter out `rustc_private` fields since with the flag
95-
// `-Zforce-unstable-if-unmarked` we consider all unmarked fields to be
96-
// unstable when building the compiler.
97-
if tcx
98-
.lookup_stability(field.did)
99-
.is_some_and(|stab| stab.is_unstable() && stab.feature != sym::rustc_private)
100-
{
101-
return InhabitedPredicate::True;
102-
}
10387
let pred = tcx.type_of(field.did).instantiate_identity().inhabited_predicate(tcx);
10488
if adt.is_enum() {
10589
return pred;

compiler/rustc_pattern_analysis/src/rustc.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::ty::{
1515
};
1616
use rustc_middle::{bug, span_bug};
1717
use rustc_session::lint;
18-
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, sym};
18+
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
1919

2020
use crate::constructor::Constructor::*;
2121
use crate::constructor::{
@@ -227,10 +227,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
227227
let is_visible =
228228
adt.is_enum() || field.vis.is_accessible_from(cx.module, cx.tcx);
229229
let is_uninhabited = cx.is_uninhabited(*ty);
230-
let is_unstable = cx.tcx.lookup_stability(field.did).is_some_and(|stab| {
231-
stab.is_unstable() && stab.feature != sym::rustc_private
232-
});
233-
let skip = is_uninhabited && (!is_visible || is_unstable);
230+
let skip = is_uninhabited && !is_visible;
234231
(ty, PrivateUninhabitedField(skip))
235232
});
236233
cx.dropless_arena.alloc_from_iter(tys)

0 commit comments

Comments
 (0)