@@ -23,15 +23,14 @@ use crate::{errors, Captures, PatCx, PrivateUninhabitedField};
23
23
use crate::constructor::Constructor::*;
24
24
25
25
// Re-export rustc-specific versions of all these types.
26
- pub type Constructor<'p, 'tcx> = crate::constructor::Constructor<RustcMatchCheckCtxt<'p, 'tcx>>;
27
- pub type ConstructorSet<'p, 'tcx> =
28
- crate::constructor::ConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>;
29
- pub type DeconstructedPat<'p, 'tcx> = crate::pat::DeconstructedPat<RustcMatchCheckCtxt<'p, 'tcx>>;
30
- pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
31
- pub type Usefulness<'p, 'tcx> = crate::usefulness::Usefulness<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
26
+ pub type Constructor<'p, 'tcx> = crate::constructor::Constructor<RustcPatCtxt<'p, 'tcx>>;
27
+ pub type ConstructorSet<'p, 'tcx> = crate::constructor::ConstructorSet<RustcPatCtxt<'p, 'tcx>>;
28
+ pub type DeconstructedPat<'p, 'tcx> = crate::pat::DeconstructedPat<RustcPatCtxt<'p, 'tcx>>;
29
+ pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcPatCtxt<'p, 'tcx>>;
30
+ pub type Usefulness<'p, 'tcx> = crate::usefulness::Usefulness<'p, RustcPatCtxt<'p, 'tcx>>;
32
31
pub type UsefulnessReport<'p, 'tcx> =
33
- crate::usefulness::UsefulnessReport<'p, RustcMatchCheckCtxt <'p, 'tcx>>;
34
- pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat<RustcMatchCheckCtxt <'p, 'tcx>>;
32
+ crate::usefulness::UsefulnessReport<'p, RustcPatCtxt <'p, 'tcx>>;
33
+ pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat<RustcPatCtxt <'p, 'tcx>>;
35
34
36
35
/// A type which has gone through `cx.reveal_opaque_ty`, i.e. if it was opaque it was replaced by
37
36
/// the hidden type if allowed in the current body. This ensures we consistently inspect the hidden
@@ -62,7 +61,7 @@ impl<'tcx> RevealedTy<'tcx> {
62
61
}
63
62
64
63
#[derive(Clone)]
65
- pub struct RustcMatchCheckCtxt <'p, 'tcx: 'p> {
64
+ pub struct RustcPatCtxt <'p, 'tcx: 'p> {
66
65
pub tcx: TyCtxt<'tcx>,
67
66
pub typeck_results: &'tcx ty::TypeckResults<'tcx>,
68
67
/// The module in which the match occurs. This is necessary for
@@ -87,22 +86,19 @@ pub struct RustcMatchCheckCtxt<'p, 'tcx: 'p> {
87
86
pub known_valid_scrutinee: bool,
88
87
}
89
88
90
- impl<'p, 'tcx: 'p> fmt::Debug for RustcMatchCheckCtxt <'p, 'tcx> {
89
+ impl<'p, 'tcx: 'p> fmt::Debug for RustcPatCtxt <'p, 'tcx> {
91
90
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
92
- f.debug_struct("RustcMatchCheckCtxt ").finish()
91
+ f.debug_struct("RustcPatCtxt ").finish()
93
92
}
94
93
}
95
94
96
- impl<'p, 'tcx: 'p> RustcMatchCheckCtxt <'p, 'tcx> {
95
+ impl<'p, 'tcx: 'p> RustcPatCtxt <'p, 'tcx> {
97
96
/// Type inference occasionally gives us opaque types in places where corresponding patterns
98
97
/// have more specific types. To avoid inconsistencies as well as detect opaque uninhabited
99
98
/// types, we use the corresponding concrete type if possible.
100
99
#[inline]
101
100
pub fn reveal_opaque_ty(&self, ty: Ty<'tcx>) -> RevealedTy<'tcx> {
102
- fn reveal_inner<'tcx>(
103
- cx: &RustcMatchCheckCtxt<'_, 'tcx>,
104
- ty: Ty<'tcx>,
105
- ) -> RevealedTy<'tcx> {
101
+ fn reveal_inner<'tcx>(cx: &RustcPatCtxt<'_, 'tcx>, ty: Ty<'tcx>) -> RevealedTy<'tcx> {
106
102
let ty::Alias(ty::Opaque, alias_ty) = *ty.kind() else { bug!() };
107
103
if let Some(local_def_id) = alias_ty.def_id.as_local() {
108
104
let key = ty::OpaqueTypeKey { def_id: local_def_id, args: alias_ty.args };
@@ -199,7 +195,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
199
195
+ ExactSizeIterator
200
196
+ Captures<'a> {
201
197
fn reveal_and_alloc<'a, 'tcx>(
202
- cx: &'a RustcMatchCheckCtxt <'_, 'tcx>,
198
+ cx: &'a RustcPatCtxt <'_, 'tcx>,
203
199
iter: impl Iterator<Item = Ty<'tcx>>,
204
200
) -> &'a [(RevealedTy<'tcx>, PrivateUninhabitedField)] {
205
201
cx.dropless_arena.alloc_from_iter(
@@ -218,7 +214,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
218
214
reveal_and_alloc(cx, once(args.type_at(0)))
219
215
} else {
220
216
let variant =
221
- &adt.variant(RustcMatchCheckCtxt ::variant_index_for_adt(&ctor, *adt));
217
+ &adt.variant(RustcPatCtxt ::variant_index_for_adt(&ctor, *adt));
222
218
223
219
// In the cases of either a `#[non_exhaustive]` field list or a non-public
224
220
// field, we skip uninhabited fields in order not to reveal the
@@ -270,7 +266,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
270
266
// patterns. If we're here we can assume this is a box pattern.
271
267
1
272
268
} else {
273
- let variant_idx = RustcMatchCheckCtxt ::variant_index_for_adt(&ctor, *adt);
269
+ let variant_idx = RustcPatCtxt ::variant_index_for_adt(&ctor, *adt);
274
270
adt.variant(variant_idx).fields.len()
275
271
}
276
272
}
@@ -506,7 +502,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
506
502
_ => bug!(),
507
503
};
508
504
let variant =
509
- &adt.variant(RustcMatchCheckCtxt ::variant_index_for_adt(&ctor, *adt));
505
+ &adt.variant(RustcPatCtxt ::variant_index_for_adt(&ctor, *adt));
510
506
arity = variant.fields.len();
511
507
fields = subpatterns
512
508
.iter()
@@ -774,8 +770,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
774
770
PatKind::Deref { subpattern: subpatterns.next().unwrap() }
775
771
}
776
772
ty::Adt(adt_def, args) => {
777
- let variant_index =
778
- RustcMatchCheckCtxt::variant_index_for_adt(&pat.ctor(), *adt_def);
773
+ let variant_index = RustcPatCtxt::variant_index_for_adt(&pat.ctor(), *adt_def);
779
774
let subpatterns = subpatterns
780
775
.enumerate()
781
776
.map(|(i, pattern)| FieldPat { field: FieldIdx::new(i), pattern })
@@ -843,7 +838,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
843
838
}
844
839
}
845
840
846
- impl<'p, 'tcx: 'p> PatCx for RustcMatchCheckCtxt <'p, 'tcx> {
841
+ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt <'p, 'tcx> {
847
842
type Ty = RevealedTy<'tcx>;
848
843
type Error = ErrorGuaranteed;
849
844
type VariantIdx = VariantIdx;
0 commit comments