@@ -261,7 +261,7 @@ impl IntRange {
261
261
/// Lint on likely incorrect range patterns (#63987)
262
262
pub ( super ) fn lint_overlapping_range_endpoints < ' a , ' p : ' a , ' tcx : ' a > (
263
263
& self ,
264
- pcx : PatCtxt < ' _ , ' p , ' tcx > ,
264
+ pcx : & PatCtxt < ' _ , ' p , ' tcx > ,
265
265
pats : impl Iterator < Item = & ' a DeconstructedPat < ' p , ' tcx > > ,
266
266
column_count : usize ,
267
267
hir_id : HirId ,
@@ -696,7 +696,7 @@ impl<'tcx> Constructor<'tcx> {
696
696
/// `EvalResult::Deny { .. }`.
697
697
///
698
698
/// This means that the variant has a stdlib unstable feature marking it.
699
- pub ( super ) fn is_unstable_variant ( & self , pcx : PatCtxt < ' _ , ' _ , ' tcx > ) -> bool {
699
+ pub ( super ) fn is_unstable_variant ( & self , pcx : & PatCtxt < ' _ , ' _ , ' tcx > ) -> bool {
700
700
if let Constructor :: Variant ( idx) = self && let ty:: Adt ( adt, _) = pcx. ty . kind ( ) {
701
701
let variant_def_id = adt. variant ( * idx) . def_id ;
702
702
// Filter variants that depend on a disabled unstable feature.
@@ -710,7 +710,7 @@ impl<'tcx> Constructor<'tcx> {
710
710
711
711
/// Checks if the `Constructor` is a `Constructor::Variant` with a `#[doc(hidden)]`
712
712
/// attribute from a type not local to the current crate.
713
- pub ( super ) fn is_doc_hidden_variant ( & self , pcx : PatCtxt < ' _ , ' _ , ' tcx > ) -> bool {
713
+ pub ( super ) fn is_doc_hidden_variant ( & self , pcx : & PatCtxt < ' _ , ' _ , ' tcx > ) -> bool {
714
714
if let Constructor :: Variant ( idx) = self && let ty:: Adt ( adt, _) = pcx. ty . kind ( ) {
715
715
let variant_def_id = adt. variants ( ) [ * idx] . def_id ;
716
716
return pcx. cx . tcx . is_doc_hidden ( variant_def_id) && !variant_def_id. is_local ( ) ;
@@ -731,7 +731,7 @@ impl<'tcx> Constructor<'tcx> {
731
731
732
732
/// The number of fields for this constructor. This must be kept in sync with
733
733
/// `Fields::wildcards`.
734
- pub ( super ) fn arity ( & self , pcx : PatCtxt < ' _ , ' _ , ' tcx > ) -> usize {
734
+ pub ( super ) fn arity ( & self , pcx : & PatCtxt < ' _ , ' _ , ' tcx > ) -> usize {
735
735
match self {
736
736
Single | Variant ( _) => match pcx. ty . kind ( ) {
737
737
ty:: Tuple ( fs) => fs. len ( ) ,
@@ -775,7 +775,7 @@ impl<'tcx> Constructor<'tcx> {
775
775
/// matrix, unless all of them are.
776
776
pub ( super ) fn split < ' a > (
777
777
& self ,
778
- pcx : PatCtxt < ' _ , ' _ , ' tcx > ,
778
+ pcx : & PatCtxt < ' _ , ' _ , ' tcx > ,
779
779
ctors : impl Iterator < Item = & ' a Constructor < ' tcx > > + Clone ,
780
780
) -> SmallVec < [ Self ; 1 ] >
781
781
where
@@ -811,7 +811,7 @@ impl<'tcx> Constructor<'tcx> {
811
811
/// this checks for inclusion.
812
812
// We inline because this has a single call site in `Matrix::specialize_constructor`.
813
813
#[ inline]
814
- pub ( super ) fn is_covered_by < ' p > ( & self , pcx : PatCtxt < ' _ , ' p , ' tcx > , other : & Self ) -> bool {
814
+ pub ( super ) fn is_covered_by < ' p > ( & self , pcx : & PatCtxt < ' _ , ' p , ' tcx > , other : & Self ) -> bool {
815
815
// This must be kept in sync with `is_covered_by_any`.
816
816
match ( self , other) {
817
817
// Wildcards cover anything
@@ -865,7 +865,7 @@ impl<'tcx> Constructor<'tcx> {
865
865
/// assumed to have been split from a wildcard.
866
866
fn is_covered_by_any < ' p > (
867
867
& self ,
868
- pcx : PatCtxt < ' _ , ' p , ' tcx > ,
868
+ pcx : & PatCtxt < ' _ , ' p , ' tcx > ,
869
869
used_ctors : & [ Constructor < ' tcx > ] ,
870
870
) -> bool {
871
871
if used_ctors. is_empty ( ) {
@@ -918,7 +918,7 @@ pub(super) struct SplitWildcard<'tcx> {
918
918
}
919
919
920
920
impl < ' tcx > SplitWildcard < ' tcx > {
921
- pub ( super ) fn new < ' p > ( pcx : PatCtxt < ' _ , ' p , ' tcx > ) -> Self {
921
+ pub ( super ) fn new < ' p > ( pcx : & PatCtxt < ' _ , ' p , ' tcx > ) -> Self {
922
922
debug ! ( "SplitWildcard::new({:?})" , pcx. ty) ;
923
923
let cx = pcx. cx ;
924
924
let make_range = |start, end| {
@@ -1044,7 +1044,7 @@ impl<'tcx> SplitWildcard<'tcx> {
1044
1044
/// do what you want.
1045
1045
pub ( super ) fn split < ' a > (
1046
1046
& mut self ,
1047
- pcx : PatCtxt < ' _ , ' _ , ' tcx > ,
1047
+ pcx : & PatCtxt < ' _ , ' _ , ' tcx > ,
1048
1048
ctors : impl Iterator < Item = & ' a Constructor < ' tcx > > + Clone ,
1049
1049
) where
1050
1050
' tcx : ' a ,
@@ -1056,21 +1056,21 @@ impl<'tcx> SplitWildcard<'tcx> {
1056
1056
}
1057
1057
1058
1058
/// Whether there are any value constructors for this type that are not present in the matrix.
1059
- fn any_missing ( & self , pcx : PatCtxt < ' _ , ' _ , ' tcx > ) -> bool {
1059
+ fn any_missing ( & self , pcx : & PatCtxt < ' _ , ' _ , ' tcx > ) -> bool {
1060
1060
self . iter_missing ( pcx) . next ( ) . is_some ( )
1061
1061
}
1062
1062
1063
1063
/// Iterate over the constructors for this type that are not present in the matrix.
1064
1064
pub ( super ) fn iter_missing < ' a , ' p > (
1065
1065
& ' a self ,
1066
- pcx : PatCtxt < ' a , ' p , ' tcx > ,
1066
+ pcx : & ' a PatCtxt < ' a , ' p , ' tcx > ,
1067
1067
) -> impl Iterator < Item = & ' a Constructor < ' tcx > > + Captures < ' p > {
1068
1068
self . all_ctors . iter ( ) . filter ( move |ctor| !ctor. is_covered_by_any ( pcx, & self . matrix_ctors ) )
1069
1069
}
1070
1070
1071
1071
/// Return the set of constructors resulting from splitting the wildcard. As explained at the
1072
1072
/// top of the file, if any constructors are missing we can ignore the present ones.
1073
- fn into_ctors ( self , pcx : PatCtxt < ' _ , ' _ , ' tcx > ) -> SmallVec < [ Constructor < ' tcx > ; 1 ] > {
1073
+ fn into_ctors ( self , pcx : & PatCtxt < ' _ , ' _ , ' tcx > ) -> SmallVec < [ Constructor < ' tcx > ; 1 ] > {
1074
1074
if self . any_missing ( pcx) {
1075
1075
// Some constructors are missing, thus we can specialize with the special `Missing`
1076
1076
// constructor, which stands for those constructors that are not seen in the matrix,
@@ -1202,35 +1202,32 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
1202
1202
1203
1203
/// Creates a new list of wildcard fields for a given constructor. The result must have a
1204
1204
/// length of `constructor.arity()`.
1205
- pub ( super ) fn wildcards (
1206
- cx : & MatchCheckCtxt < ' p , ' tcx > ,
1207
- ty : Ty < ' tcx > ,
1208
- constructor : & Constructor < ' tcx > ,
1209
- ) -> Self {
1205
+ #[ instrument( level = "trace" ) ]
1206
+ pub ( super ) fn wildcards ( pcx : & PatCtxt < ' _ , ' p , ' tcx > , constructor : & Constructor < ' tcx > ) -> Self {
1210
1207
let ret = match constructor {
1211
- Single | Variant ( _) => match ty. kind ( ) {
1212
- ty:: Tuple ( fs) => Fields :: wildcards_from_tys ( cx, fs. iter ( ) ) ,
1213
- ty:: Ref ( _, rty, _) => Fields :: wildcards_from_tys ( cx, once ( * rty) ) ,
1208
+ Single | Variant ( _) => match pcx . ty . kind ( ) {
1209
+ ty:: Tuple ( fs) => Fields :: wildcards_from_tys ( pcx . cx , fs. iter ( ) ) ,
1210
+ ty:: Ref ( _, rty, _) => Fields :: wildcards_from_tys ( pcx . cx , once ( * rty) ) ,
1214
1211
ty:: Adt ( adt, substs) => {
1215
1212
if adt. is_box ( ) {
1216
1213
// The only legal patterns of type `Box` (outside `std`) are `_` and box
1217
1214
// patterns. If we're here we can assume this is a box pattern.
1218
- Fields :: wildcards_from_tys ( cx, once ( substs. type_at ( 0 ) ) )
1215
+ Fields :: wildcards_from_tys ( pcx . cx , once ( substs. type_at ( 0 ) ) )
1219
1216
} else {
1220
1217
let variant = & adt. variant ( constructor. variant_index_for_adt ( * adt) ) ;
1221
- let tys = Fields :: list_variant_nonhidden_fields ( cx, ty, variant)
1218
+ let tys = Fields :: list_variant_nonhidden_fields ( pcx . cx , pcx . ty , variant)
1222
1219
. map ( |( _, ty) | ty) ;
1223
- Fields :: wildcards_from_tys ( cx, tys)
1220
+ Fields :: wildcards_from_tys ( pcx . cx , tys)
1224
1221
}
1225
1222
}
1226
- _ => bug ! ( "Unexpected type for `Single` constructor: {:?}" , ty ) ,
1223
+ _ => bug ! ( "Unexpected type for `Single` constructor: {:?}" , pcx ) ,
1227
1224
} ,
1228
- Slice ( slice) => match * ty. kind ( ) {
1225
+ Slice ( slice) => match * pcx . ty . kind ( ) {
1229
1226
ty:: Slice ( ty) | ty:: Array ( ty, _) => {
1230
1227
let arity = slice. arity ( ) ;
1231
- Fields :: wildcards_from_tys ( cx, ( 0 ..arity) . map ( |_| ty) )
1228
+ Fields :: wildcards_from_tys ( pcx . cx , ( 0 ..arity) . map ( |_| ty) )
1232
1229
}
1233
- _ => bug ! ( "bad slice pattern {:?} {:?}" , constructor, ty ) ,
1230
+ _ => bug ! ( "bad slice pattern {:?} {:?}" , constructor, pcx ) ,
1234
1231
} ,
1235
1232
Str ( ..)
1236
1233
| FloatRange ( ..)
@@ -1243,7 +1240,7 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
1243
1240
bug ! ( "called `Fields::wildcards` on an `Or` ctor" )
1244
1241
}
1245
1242
} ;
1246
- debug ! ( "Fields::wildcards({:?}, {:?}) = {:#?}" , constructor , ty , ret) ;
1243
+ debug ! ( ? ret) ;
1247
1244
ret
1248
1245
}
1249
1246
@@ -1285,8 +1282,8 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
1285
1282
/// Construct a pattern that matches everything that starts with this constructor.
1286
1283
/// For example, if `ctor` is a `Constructor::Variant` for `Option::Some`, we get the pattern
1287
1284
/// `Some(_)`.
1288
- pub ( super ) fn wild_from_ctor ( pcx : PatCtxt < ' _ , ' p , ' tcx > , ctor : Constructor < ' tcx > ) -> Self {
1289
- let fields = Fields :: wildcards ( pcx. cx , pcx . ty , & ctor) ;
1285
+ pub ( super ) fn wild_from_ctor ( pcx : & PatCtxt < ' _ , ' p , ' tcx > , ctor : Constructor < ' tcx > ) -> Self {
1286
+ let fields = Fields :: wildcards ( pcx, & ctor) ;
1290
1287
DeconstructedPat :: new ( ctor, fields, pcx. ty , DUMMY_SP )
1291
1288
}
1292
1289
@@ -1553,13 +1550,13 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
1553
1550
/// `other_ctor` can be different from `self.ctor`, but must be covered by it.
1554
1551
pub ( super ) fn specialize < ' a > (
1555
1552
& ' a self ,
1556
- cx : & MatchCheckCtxt < ' p , ' tcx > ,
1553
+ pcx : & PatCtxt < ' _ , ' p , ' tcx > ,
1557
1554
other_ctor : & Constructor < ' tcx > ,
1558
1555
) -> SmallVec < [ & ' p DeconstructedPat < ' p , ' tcx > ; 2 ] > {
1559
1556
match ( & self . ctor , other_ctor) {
1560
1557
( Wildcard , _) => {
1561
1558
// We return a wildcard for each field of `other_ctor`.
1562
- Fields :: wildcards ( cx , self . ty , other_ctor) . iter_patterns ( ) . collect ( )
1559
+ Fields :: wildcards ( pcx , other_ctor) . iter_patterns ( ) . collect ( )
1563
1560
}
1564
1561
( Slice ( self_slice) , Slice ( other_slice) )
1565
1562
if self_slice. arity ( ) != other_slice. arity ( ) =>
@@ -1578,7 +1575,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
1578
1575
let prefix = & self . fields . fields [ ..prefix] ;
1579
1576
let suffix = & self . fields . fields [ self_slice. arity ( ) - suffix..] ;
1580
1577
let wildcard: & _ =
1581
- cx. pattern_arena . alloc ( DeconstructedPat :: wildcard ( inner_ty) ) ;
1578
+ pcx . cx . pattern_arena . alloc ( DeconstructedPat :: wildcard ( inner_ty) ) ;
1582
1579
let extra_wildcards = other_slice. arity ( ) - self_slice. arity ( ) ;
1583
1580
let extra_wildcards = ( 0 ..extra_wildcards) . map ( |_| wildcard) ;
1584
1581
prefix. iter ( ) . chain ( extra_wildcards) . chain ( suffix) . collect ( )
0 commit comments