@@ -25,19 +25,23 @@ use crate::MatchCx;
25
25
use crate :: constructor:: Constructor :: * ;
26
26
27
27
// 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 > > ;
33
36
pub ( crate ) type SplitConstructorSet < ' p , ' tcx > =
34
- crate :: constructor:: SplitConstructorSet < RustcCtxt < ' p , ' tcx > > ;
37
+ crate :: constructor:: SplitConstructorSet < RustcMatchCheckCtxt < ' p , ' tcx > > ;
35
38
pub 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 > > ;
38
42
39
43
#[ derive( Clone ) ]
40
- pub struct RustcCtxt < ' p , ' tcx > {
44
+ pub struct RustcMatchCheckCtxt < ' p , ' tcx > {
41
45
pub tcx : TyCtxt < ' tcx > ,
42
46
/// The module in which the match occurs. This is necessary for
43
47
/// checking inhabited-ness of types because whether a type is (visibly)
@@ -61,13 +65,13 @@ pub struct RustcCtxt<'p, 'tcx> {
61
65
pub known_valid_scrutinee : bool ,
62
66
}
63
67
64
- impl < ' p , ' tcx > fmt:: Debug for RustcCtxt < ' p , ' tcx > {
68
+ impl < ' p , ' tcx > fmt:: Debug for RustcMatchCheckCtxt < ' p , ' tcx > {
65
69
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
66
- f. debug_struct ( "RustcCtxt " ) . finish ( )
70
+ f. debug_struct ( "RustcMatchCheckCtxt " ) . finish ( )
67
71
}
68
72
}
69
73
70
- impl < ' p , ' tcx > RustcCtxt < ' p , ' tcx > {
74
+ impl < ' p , ' tcx > RustcMatchCheckCtxt < ' p , ' tcx > {
71
75
pub ( crate ) fn is_uninhabited ( & self , ty : Ty < ' tcx > ) -> bool {
72
76
!ty. is_inhabited_from ( self . tcx , self . module , self . param_env )
73
77
}
@@ -152,7 +156,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
152
156
// patterns. If we're here we can assume this is a box pattern.
153
157
cx. dropless_arena . alloc_from_iter ( once ( args. type_at ( 0 ) ) )
154
158
} 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) ) ;
156
161
let tys = cx. list_variant_nonhidden_fields ( ty, variant) . map ( |( _, ty) | ty) ;
157
162
cx. dropless_arena . alloc_from_iter ( tys)
158
163
}
@@ -197,7 +202,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
197
202
// patterns. If we're here we can assume this is a box pattern.
198
203
1
199
204
} 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) ) ;
201
207
self . list_variant_nonhidden_fields ( ty, variant) . count ( )
202
208
}
203
209
}
@@ -428,7 +434,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
428
434
PatKind :: Variant { variant_index, .. } => Variant ( variant_index) ,
429
435
_ => bug ! ( ) ,
430
436
} ;
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) ) ;
432
439
// For each field in the variant, we store the relevant index into `self.fields` if any.
433
440
let mut field_id_to_id: Vec < Option < usize > > =
434
441
( 0 ..variant. fields . len ( ) ) . map ( |_| None ) . collect ( ) ;
@@ -687,7 +694,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
687
694
PatKind :: Deref { subpattern : subpatterns. next ( ) . unwrap ( ) }
688
695
}
689
696
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) ;
691
699
let variant = & adt_def. variant ( variant_index) ;
692
700
let subpatterns = cx
693
701
. list_variant_nonhidden_fields ( pat. ty ( ) , variant)
@@ -782,13 +790,14 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
782
790
write ! ( f, "box {subpattern:?}" )
783
791
}
784
792
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
+ } ;
792
801
793
802
if let Some ( variant) = variant {
794
803
write ! ( f, "{}" , variant. name) ?;
@@ -853,7 +862,7 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
853
862
}
854
863
}
855
864
856
- impl < ' p , ' tcx > MatchCx for RustcCtxt < ' p , ' tcx > {
865
+ impl < ' p , ' tcx > MatchCx for RustcMatchCheckCtxt < ' p , ' tcx > {
857
866
type Ty = Ty < ' tcx > ;
858
867
type Span = Span ;
859
868
type VariantIdx = VariantIdx ;
0 commit comments