@@ -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
@@ -1286,7 +1283,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
1286
1283
/// For example, if `ctor` is a `Constructor::Variant` for `Option::Some`, we get the pattern
1287
1284
/// `Some(_)`.
1288
1285
pub ( super ) fn wild_from_ctor ( pcx : PatCtxt < ' _ , ' p , ' tcx > , ctor : Constructor < ' tcx > ) -> Self {
1289
- let fields = Fields :: wildcards ( pcx. cx , pcx . ty , & ctor) ;
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