@@ -23,15 +23,14 @@ use crate::{errors, Captures, PatCx, PrivateUninhabitedField};
2323use crate :: constructor:: Constructor :: * ;
2424
2525// 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 > > ;
3231pub 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 > > ;
3534
3635/// A type which has gone through `cx.reveal_opaque_ty`, i.e. if it was opaque it was replaced by
3736/// the hidden type if allowed in the current body. This ensures we consistently inspect the hidden
@@ -62,7 +61,7 @@ impl<'tcx> RevealedTy<'tcx> {
6261}
6362
6463#[ derive( Clone ) ]
65- pub struct RustcMatchCheckCtxt < ' p , ' tcx : ' p > {
64+ pub struct RustcPatCtxt < ' p , ' tcx : ' p > {
6665 pub tcx : TyCtxt < ' tcx > ,
6766 pub typeck_results : & ' tcx ty:: TypeckResults < ' tcx > ,
6867 /// The module in which the match occurs. This is necessary for
@@ -87,22 +86,19 @@ pub struct RustcMatchCheckCtxt<'p, 'tcx: 'p> {
8786 pub known_valid_scrutinee : bool ,
8887}
8988
90- impl < ' p , ' tcx : ' p > fmt:: Debug for RustcMatchCheckCtxt < ' p , ' tcx > {
89+ impl < ' p , ' tcx : ' p > fmt:: Debug for RustcPatCtxt < ' p , ' tcx > {
9190 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
92- f. debug_struct ( "RustcMatchCheckCtxt " ) . finish ( )
91+ f. debug_struct ( "RustcPatCtxt " ) . finish ( )
9392 }
9493}
9594
96- impl < ' p , ' tcx : ' p > RustcMatchCheckCtxt < ' p , ' tcx > {
95+ impl < ' p , ' tcx : ' p > RustcPatCtxt < ' p , ' tcx > {
9796 /// Type inference occasionally gives us opaque types in places where corresponding patterns
9897 /// have more specific types. To avoid inconsistencies as well as detect opaque uninhabited
9998 /// types, we use the corresponding concrete type if possible.
10099 #[ inline]
101100 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 > {
106102 let ty:: Alias ( ty:: Opaque , alias_ty) = * ty. kind ( ) else { bug ! ( ) } ;
107103 if let Some ( local_def_id) = alias_ty. def_id . as_local ( ) {
108104 let key = ty:: OpaqueTypeKey { def_id : local_def_id, args : alias_ty. args } ;
@@ -199,7 +195,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
199195 + ExactSizeIterator
200196 + Captures < ' a > {
201197 fn reveal_and_alloc < ' a , ' tcx > (
202- cx : & ' a RustcMatchCheckCtxt < ' _ , ' tcx > ,
198+ cx : & ' a RustcPatCtxt < ' _ , ' tcx > ,
203199 iter : impl Iterator < Item = Ty < ' tcx > > ,
204200 ) -> & ' a [ ( RevealedTy < ' tcx > , PrivateUninhabitedField ) ] {
205201 cx. dropless_arena . alloc_from_iter (
@@ -218,7 +214,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
218214 reveal_and_alloc ( cx, once ( args. type_at ( 0 ) ) )
219215 } else {
220216 let variant =
221- & adt. variant ( RustcMatchCheckCtxt :: variant_index_for_adt ( & ctor, * adt) ) ;
217+ & adt. variant ( RustcPatCtxt :: variant_index_for_adt ( & ctor, * adt) ) ;
222218
223219 // In the cases of either a `#[non_exhaustive]` field list or a non-public
224220 // field, we skip uninhabited fields in order not to reveal the
@@ -270,7 +266,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
270266 // patterns. If we're here we can assume this is a box pattern.
271267 1
272268 } else {
273- let variant_idx = RustcMatchCheckCtxt :: variant_index_for_adt ( & ctor, * adt) ;
269+ let variant_idx = RustcPatCtxt :: variant_index_for_adt ( & ctor, * adt) ;
274270 adt. variant ( variant_idx) . fields . len ( )
275271 }
276272 }
@@ -506,7 +502,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
506502 _ => bug ! ( ) ,
507503 } ;
508504 let variant =
509- & adt. variant ( RustcMatchCheckCtxt :: variant_index_for_adt ( & ctor, * adt) ) ;
505+ & adt. variant ( RustcPatCtxt :: variant_index_for_adt ( & ctor, * adt) ) ;
510506 arity = variant. fields . len ( ) ;
511507 fields = subpatterns
512508 . iter ( )
@@ -774,8 +770,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
774770 PatKind :: Deref { subpattern : subpatterns. next ( ) . unwrap ( ) }
775771 }
776772 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) ;
779774 let subpatterns = subpatterns
780775 . enumerate ( )
781776 . map ( |( i, pattern) | FieldPat { field : FieldIdx :: new ( i) , pattern } )
@@ -843,7 +838,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
843838 }
844839}
845840
846- impl < ' p , ' tcx : ' p > PatCx for RustcMatchCheckCtxt < ' p , ' tcx > {
841+ impl < ' p , ' tcx : ' p > PatCx for RustcPatCtxt < ' p , ' tcx > {
847842 type Ty = RevealedTy < ' tcx > ;
848843 type Error = ErrorGuaranteed ;
849844 type VariantIdx = VariantIdx ;
0 commit comments