Skip to content

Commit c918893

Browse files
committed
Rename Skip to PrivateUninhabited
1 parent 39441e4 commit c918893

File tree

5 files changed

+38
-33
lines changed

5 files changed

+38
-33
lines changed

Diff for: compiler/rustc_pattern_analysis/src/constructor.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,9 @@ pub enum Constructor<Cx: TypeCx> {
688688
/// Fake extra constructor for constructors that are not seen in the matrix, as explained at the
689689
/// top of the file.
690690
Missing,
691-
/// Fake extra constructor that indicates that we should skip the column entirely. This is used
692-
/// when a private field is empty, so that we don't observe its emptiness. Only used for
693-
/// specialization.
694-
Skip,
691+
/// Fake extra constructor that indicates and empty field that is private. When we encounter one
692+
/// we skip the column entirely so we don't observe its emptiness. Only used for specialization.
693+
PrivateUninhabited,
695694
}
696695

697696
impl<Cx: TypeCx> Clone for Constructor<Cx> {
@@ -713,7 +712,7 @@ impl<Cx: TypeCx> Clone for Constructor<Cx> {
713712
Constructor::NonExhaustive => Constructor::NonExhaustive,
714713
Constructor::Hidden => Constructor::Hidden,
715714
Constructor::Missing => Constructor::Missing,
716-
Constructor::Skip => Constructor::Skip,
715+
Constructor::PrivateUninhabited => Constructor::PrivateUninhabited,
717716
}
718717
}
719718
}
@@ -768,8 +767,8 @@ impl<Cx: TypeCx> Constructor<Cx> {
768767
}
769768
// Wildcards cover anything
770769
(_, Wildcard) => true,
771-
// `Skip` skips everything.
772-
(Skip, _) => true,
770+
// `PrivateUninhabited` skips everything.
771+
(PrivateUninhabited, _) => true,
773772
// Only a wildcard pattern can match these special constructors.
774773
(Missing { .. } | NonExhaustive | Hidden, _) => false,
775774

Diff for: compiler/rustc_pattern_analysis/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ use crate::usefulness::{compute_match_usefulness, ValidityConstraint};
8282
pub trait Captures<'a> {}
8383
impl<'a, T: ?Sized> Captures<'a> for T {}
8484

85-
/// `bool` newtype that indicates whether we should skip this field during analysis.
85+
/// `bool` newtype that indicates whether this is a privately uninhabited field that we should skip
86+
/// during analysis.
8687
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
87-
pub struct SkipField(pub bool);
88+
pub struct PrivateUninhabitedField(pub bool);
8889

8990
/// Context that provides type information about constructors.
9091
///
@@ -114,7 +115,7 @@ pub trait TypeCx: Sized + fmt::Debug {
114115
&'a self,
115116
ctor: &'a Constructor<Self>,
116117
ty: &'a Self::Ty,
117-
) -> impl Iterator<Item = (Self::Ty, SkipField)> + ExactSizeIterator + Captures<'a>;
118+
) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a>;
118119

119120
/// The set of all the constructors for `ty`.
120121
///

Diff for: compiler/rustc_pattern_analysis/src/pat.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fmt;
55
use smallvec::{smallvec, SmallVec};
66

77
use crate::constructor::{Constructor, Slice, SliceKind};
8-
use crate::{SkipField, TypeCx};
8+
use crate::{PrivateUninhabitedField, TypeCx};
99

1010
use self::Constructor::*;
1111

@@ -80,7 +80,7 @@ impl<Cx: TypeCx> DeconstructedPat<Cx> {
8080
// Return a wildcard for each field of `other_ctor`.
8181
(Wildcard, _) => wildcard_sub_tys(),
8282
// Skip this column.
83-
(_, Skip) => smallvec![],
83+
(_, PrivateUninhabited) => smallvec![],
8484
// The only non-trivial case: two slices of different arity. `other_slice` is
8585
// guaranteed to have a larger arity, so we fill the middle part with enough
8686
// wildcards to reach the length of the new, larger slice.
@@ -189,7 +189,9 @@ impl<Cx: TypeCx> fmt::Debug for DeconstructedPat<Cx> {
189189
}
190190
Ok(())
191191
}
192-
Wildcard | Missing | NonExhaustive | Hidden | Skip => write!(f, "_ : {:?}", pat.ty()),
192+
Wildcard | Missing | NonExhaustive | Hidden | PrivateUninhabited => {
193+
write!(f, "_ : {:?}", pat.ty())
194+
}
193195
}
194196
}
195197
}
@@ -299,7 +301,7 @@ impl<Cx: TypeCx> WitnessPat<Cx> {
299301
pub(crate) fn wild_from_ctor(cx: &Cx, ctor: Constructor<Cx>, ty: Cx::Ty) -> Self {
300302
let fields = cx
301303
.ctor_sub_tys(&ctor, &ty)
302-
.filter(|(_, SkipField(skip))| !skip)
304+
.filter(|(_, PrivateUninhabitedField(skip))| !skip)
303305
.map(|(ty, _)| Self::wildcard(ty))
304306
.collect();
305307
Self::new(ctor, fields, ty)

Diff for: compiler/rustc_pattern_analysis/src/rustc.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_target::abi::{FieldIdx, Integer, VariantIdx, FIRST_VARIANT};
1818
use crate::constructor::{
1919
IntRange, MaybeInfiniteInt, OpaqueId, RangeEnd, Slice, SliceKind, VariantVisibility,
2020
};
21-
use crate::{errors, Captures, SkipField, TypeCx};
21+
use crate::{errors, Captures, PrivateUninhabitedField, TypeCx};
2222

2323
use crate::constructor::Constructor::*;
2424

@@ -195,14 +195,16 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
195195
&'a self,
196196
ctor: &'a Constructor<'p, 'tcx>,
197197
ty: RevealedTy<'tcx>,
198-
) -> impl Iterator<Item = (RevealedTy<'tcx>, SkipField)> + ExactSizeIterator + Captures<'a>
199-
{
198+
) -> impl Iterator<Item = (RevealedTy<'tcx>, PrivateUninhabitedField)>
199+
+ ExactSizeIterator
200+
+ Captures<'a> {
200201
fn reveal_and_alloc<'a, 'tcx>(
201202
cx: &'a RustcMatchCheckCtxt<'_, 'tcx>,
202203
iter: impl Iterator<Item = Ty<'tcx>>,
203-
) -> &'a [(RevealedTy<'tcx>, SkipField)] {
204+
) -> &'a [(RevealedTy<'tcx>, PrivateUninhabitedField)] {
204205
cx.dropless_arena.alloc_from_iter(
205-
iter.map(|ty| cx.reveal_opaque_ty(ty)).map(|ty| (ty, SkipField(false))),
206+
iter.map(|ty| cx.reveal_opaque_ty(ty))
207+
.map(|ty| (ty, PrivateUninhabitedField(false))),
206208
)
207209
}
208210
let cx = self;
@@ -230,7 +232,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
230232
|| cx.tcx.features().min_exhaustive_patterns)
231233
&& cx.is_uninhabited(*ty);
232234
let skip = is_uninhabited && (!is_visible || is_non_exhaustive);
233-
(ty, SkipField(skip))
235+
(ty, PrivateUninhabitedField(skip))
234236
});
235237
cx.dropless_arena.alloc_from_iter(tys)
236238
}
@@ -249,7 +251,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
249251
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty),
250252
},
251253
Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..)
252-
| NonExhaustive | Hidden | Missing | Skip | Wildcard => &[],
254+
| NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => &[],
253255
Or => {
254256
bug!("called `Fields::wildcards` on an `Or` ctor")
255257
}
@@ -277,7 +279,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
277279
Ref => 1,
278280
Slice(slice) => slice.arity(),
279281
Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..)
280-
| NonExhaustive | Hidden | Missing | Skip | Wildcard => 0,
282+
| NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => 0,
281283
Or => bug!("The `Or` constructor doesn't have a fixed arity"),
282284
}
283285
}
@@ -805,7 +807,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
805807
}
806808
}
807809
&Str(value) => PatKind::Constant { value },
808-
Wildcard | NonExhaustive | Hidden | Skip => PatKind::Wild,
810+
Wildcard | NonExhaustive | Hidden | PrivateUninhabited => PatKind::Wild,
809811
Missing { .. } => bug!(
810812
"trying to convert a `Missing` constructor into a `Pat`; this is probably a bug,
811813
`Missing` should have been processed in `apply_constructors`"
@@ -841,7 +843,8 @@ impl<'p, 'tcx: 'p> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
841843
&'a self,
842844
ctor: &'a crate::constructor::Constructor<Self>,
843845
ty: &'a Self::Ty,
844-
) -> impl Iterator<Item = (Self::Ty, SkipField)> + ExactSizeIterator + Captures<'a> {
846+
) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a>
847+
{
845848
self.ctor_sub_tys(ctor, *ty)
846849
}
847850
fn ctors_for_ty(

Diff for: compiler/rustc_pattern_analysis/src/usefulness.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ use std::fmt;
716716

717717
use crate::constructor::{Constructor, ConstructorSet, IntRange};
718718
use crate::pat::{DeconstructedPat, PatId, PatOrWild, WitnessPat};
719-
use crate::{Captures, MatchArm, SkipField, TypeCx};
719+
use crate::{Captures, MatchArm, PrivateUninhabitedField, TypeCx};
720720

721721
use self::ValidityConstraint::*;
722722

@@ -817,9 +817,9 @@ impl fmt::Display for ValidityConstraint {
817817
struct PlaceInfo<Cx: TypeCx> {
818818
/// The type of the place.
819819
ty: Cx::Ty,
820-
/// Whether we must skip this field during analysis. This is used when a private field is empty,
820+
/// Whether the place is a private uninhabited field. If so we skip this field during analysis
821821
/// so that we don't observe its emptiness.
822-
skip: SkipField,
822+
private_uninhabited: bool,
823823
/// Whether the place is known to contain valid data.
824824
validity: ValidityConstraint,
825825
/// Whether the place is the scrutinee itself or a subplace of it.
@@ -836,9 +836,9 @@ impl<Cx: TypeCx> PlaceInfo<Cx> {
836836
) -> impl Iterator<Item = Self> + ExactSizeIterator + Captures<'a> {
837837
let ctor_sub_tys = cx.ctor_sub_tys(ctor, &self.ty);
838838
let ctor_sub_validity = self.validity.specialize(ctor);
839-
ctor_sub_tys.map(move |(ty, skip)| PlaceInfo {
839+
ctor_sub_tys.map(move |(ty, PrivateUninhabitedField(private_uninhabited))| PlaceInfo {
840840
ty,
841-
skip,
841+
private_uninhabited,
842842
validity: ctor_sub_validity,
843843
is_scrutinee: false,
844844
})
@@ -860,9 +860,9 @@ impl<Cx: TypeCx> PlaceInfo<Cx> {
860860
where
861861
Cx: 'a,
862862
{
863-
if matches!(self.skip, SkipField(true)) {
863+
if self.private_uninhabited {
864864
// Skip the whole column
865-
return Ok((smallvec![Constructor::Skip], vec![]));
865+
return Ok((smallvec![Constructor::PrivateUninhabited], vec![]));
866866
}
867867

868868
let ctors_for_ty = cx.ctors_for_ty(&self.ty)?;
@@ -925,7 +925,7 @@ impl<Cx: TypeCx> Clone for PlaceInfo<Cx> {
925925
fn clone(&self) -> Self {
926926
Self {
927927
ty: self.ty.clone(),
928-
skip: self.skip,
928+
private_uninhabited: self.private_uninhabited,
929929
validity: self.validity,
930930
is_scrutinee: self.is_scrutinee,
931931
}
@@ -1137,7 +1137,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
11371137
) -> Self {
11381138
let place_info = PlaceInfo {
11391139
ty: scrut_ty,
1140-
skip: SkipField(false),
1140+
private_uninhabited: false,
11411141
validity: scrut_validity,
11421142
is_scrutinee: true,
11431143
};

0 commit comments

Comments
 (0)