@@ -25,19 +25,23 @@ use crate::MatchCx;
2525use crate :: constructor:: Constructor :: * ;
2626
2727// Re-export rustc-specific versions of all these types.
28- pub type Constructor < ' p , ' tcx > = crate :: constructor:: Constructor < RustcCtxt < ' p , ' tcx > > ;
29- pub type ConstructorSet < ' p , ' tcx > = crate :: constructor:: ConstructorSet < RustcCtxt < ' p , ' tcx > > ;
30- pub type DeconstructedPat < ' p , ' tcx > = crate :: pat:: DeconstructedPat < ' p , RustcCtxt < ' p , ' tcx > > ;
31- pub type MatchArm < ' p , ' tcx > = crate :: MatchArm < ' p , RustcCtxt < ' p , ' tcx > > ;
32- pub ( crate ) type PatCtxt < ' a , ' p , ' tcx > = crate :: usefulness:: PatCtxt < ' a , ' p , RustcCtxt < ' p , ' tcx > > ;
28+ pub type Constructor < ' p , ' tcx > = crate :: constructor:: Constructor < RustcMatchCheckCtxt < ' p , ' tcx > > ;
29+ pub type ConstructorSet < ' p , ' tcx > =
30+ crate :: constructor:: ConstructorSet < RustcMatchCheckCtxt < ' p , ' tcx > > ;
31+ pub type DeconstructedPat < ' p , ' tcx > =
32+ crate :: pat:: DeconstructedPat < ' p , RustcMatchCheckCtxt < ' p , ' tcx > > ;
33+ pub type MatchArm < ' p , ' tcx > = crate :: MatchArm < ' p , RustcMatchCheckCtxt < ' p , ' tcx > > ;
34+ pub ( crate ) type PatCtxt < ' a , ' p , ' tcx > =
35+ crate :: usefulness:: PatCtxt < ' a , ' p , RustcMatchCheckCtxt < ' p , ' tcx > > ;
3336pub ( crate ) type SplitConstructorSet < ' p , ' tcx > =
34- crate :: constructor:: SplitConstructorSet < RustcCtxt < ' p , ' tcx > > ;
37+ crate :: constructor:: SplitConstructorSet < RustcMatchCheckCtxt < ' p , ' tcx > > ;
3538pub type Usefulness = crate :: usefulness:: Usefulness < Span > ;
36- pub type UsefulnessReport < ' p , ' tcx > = crate :: usefulness:: UsefulnessReport < ' p , RustcCtxt < ' p , ' tcx > > ;
37- pub type WitnessPat < ' p , ' tcx > = crate :: pat:: WitnessPat < RustcCtxt < ' p , ' tcx > > ;
39+ pub type UsefulnessReport < ' p , ' tcx > =
40+ crate :: usefulness:: UsefulnessReport < ' p , RustcMatchCheckCtxt < ' p , ' tcx > > ;
41+ pub type WitnessPat < ' p , ' tcx > = crate :: pat:: WitnessPat < RustcMatchCheckCtxt < ' p , ' tcx > > ;
3842
3943#[ derive( Clone ) ]
40- pub struct RustcCtxt < ' p , ' tcx > {
44+ pub struct RustcMatchCheckCtxt < ' p , ' tcx > {
4145 pub tcx : TyCtxt < ' tcx > ,
4246 /// The module in which the match occurs. This is necessary for
4347 /// checking inhabited-ness of types because whether a type is (visibly)
@@ -61,13 +65,13 @@ pub struct RustcCtxt<'p, 'tcx> {
6165 pub known_valid_scrutinee : bool ,
6266}
6367
64- impl < ' p , ' tcx > fmt:: Debug for RustcCtxt < ' p , ' tcx > {
68+ impl < ' p , ' tcx > fmt:: Debug for RustcMatchCheckCtxt < ' p , ' tcx > {
6569 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
66- f. debug_struct ( "RustcCtxt " ) . finish ( )
70+ f. debug_struct ( "RustcMatchCheckCtxt " ) . finish ( )
6771 }
6872}
6973
70- impl < ' p , ' tcx > RustcCtxt < ' p , ' tcx > {
74+ impl < ' p , ' tcx > RustcMatchCheckCtxt < ' p , ' tcx > {
7175 pub ( crate ) fn is_uninhabited ( & self , ty : Ty < ' tcx > ) -> bool {
7276 !ty. is_inhabited_from ( self . tcx , self . module , self . param_env )
7377 }
@@ -152,7 +156,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
152156 // patterns. If we're here we can assume this is a box pattern.
153157 cx. dropless_arena . alloc_from_iter ( once ( args. type_at ( 0 ) ) )
154158 } else {
155- let variant = & adt. variant ( RustcCtxt :: variant_index_for_adt ( & ctor, * adt) ) ;
159+ let variant =
160+ & adt. variant ( RustcMatchCheckCtxt :: variant_index_for_adt ( & ctor, * adt) ) ;
156161 let tys = cx. list_variant_nonhidden_fields ( ty, variant) . map ( |( _, ty) | ty) ;
157162 cx. dropless_arena . alloc_from_iter ( tys)
158163 }
@@ -197,7 +202,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
197202 // patterns. If we're here we can assume this is a box pattern.
198203 1
199204 } else {
200- let variant = & adt. variant ( RustcCtxt :: variant_index_for_adt ( & ctor, * adt) ) ;
205+ let variant =
206+ & adt. variant ( RustcMatchCheckCtxt :: variant_index_for_adt ( & ctor, * adt) ) ;
201207 self . list_variant_nonhidden_fields ( ty, variant) . count ( )
202208 }
203209 }
@@ -428,7 +434,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
428434 PatKind :: Variant { variant_index, .. } => Variant ( variant_index) ,
429435 _ => bug ! ( ) ,
430436 } ;
431- let variant = & adt. variant ( RustcCtxt :: variant_index_for_adt ( & ctor, * adt) ) ;
437+ let variant =
438+ & adt. variant ( RustcMatchCheckCtxt :: variant_index_for_adt ( & ctor, * adt) ) ;
432439 // For each field in the variant, we store the relevant index into `self.fields` if any.
433440 let mut field_id_to_id: Vec < Option < usize > > =
434441 ( 0 ..variant. fields . len ( ) ) . map ( |_| None ) . collect ( ) ;
@@ -687,7 +694,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
687694 PatKind :: Deref { subpattern : subpatterns. next ( ) . unwrap ( ) }
688695 }
689696 ty:: Adt ( adt_def, args) => {
690- let variant_index = RustcCtxt :: variant_index_for_adt ( & pat. ctor ( ) , * adt_def) ;
697+ let variant_index =
698+ RustcMatchCheckCtxt :: variant_index_for_adt ( & pat. ctor ( ) , * adt_def) ;
691699 let variant = & adt_def. variant ( variant_index) ;
692700 let subpatterns = cx
693701 . list_variant_nonhidden_fields ( pat. ty ( ) , variant)
@@ -782,13 +790,14 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
782790 write ! ( f, "box {subpattern:?}" )
783791 }
784792 ty:: Adt ( ..) | ty:: Tuple ( ..) => {
785- let variant = match pat. ty ( ) . kind ( ) {
786- ty:: Adt ( adt, _) => {
787- Some ( adt. variant ( RustcCtxt :: variant_index_for_adt ( pat. ctor ( ) , * adt) ) )
788- }
789- ty:: Tuple ( _) => None ,
790- _ => unreachable ! ( ) ,
791- } ;
793+ let variant =
794+ match pat. ty ( ) . kind ( ) {
795+ ty:: Adt ( adt, _) => Some ( adt. variant (
796+ RustcMatchCheckCtxt :: variant_index_for_adt ( pat. ctor ( ) , * adt) ,
797+ ) ) ,
798+ ty:: Tuple ( _) => None ,
799+ _ => unreachable ! ( ) ,
800+ } ;
792801
793802 if let Some ( variant) = variant {
794803 write ! ( f, "{}" , variant. name) ?;
@@ -853,7 +862,7 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
853862 }
854863}
855864
856- impl < ' p , ' tcx > MatchCx for RustcCtxt < ' p , ' tcx > {
865+ impl < ' p , ' tcx > MatchCx for RustcMatchCheckCtxt < ' p , ' tcx > {
857866 type Ty = Ty < ' tcx > ;
858867 type Span = Span ;
859868 type VariantIdx = VariantIdx ;
0 commit comments