@@ -1154,8 +1154,9 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
1154
1154
fn wildcards_from_tys (
1155
1155
cx : & MatchCheckCtxt < ' p , ' tcx > ,
1156
1156
tys : impl IntoIterator < Item = Ty < ' tcx > > ,
1157
+ span : Span ,
1157
1158
) -> Self {
1158
- Fields :: from_iter ( cx, tys. into_iter ( ) . map ( DeconstructedPat :: wildcard) )
1159
+ Fields :: from_iter ( cx, tys. into_iter ( ) . map ( |ty| DeconstructedPat :: wildcard ( ty , span ) ) )
1159
1160
}
1160
1161
1161
1162
// In the cases of either a `#[non_exhaustive]` field list or a non-public field, we hide
@@ -1191,26 +1192,26 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
1191
1192
pub ( super ) fn wildcards ( pcx : & PatCtxt < ' _ , ' p , ' tcx > , constructor : & Constructor < ' tcx > ) -> Self {
1192
1193
let ret = match constructor {
1193
1194
Single | Variant ( _) => match pcx. ty . kind ( ) {
1194
- ty:: Tuple ( fs) => Fields :: wildcards_from_tys ( pcx. cx , fs. iter ( ) ) ,
1195
- ty:: Ref ( _, rty, _) => Fields :: wildcards_from_tys ( pcx. cx , once ( * rty) ) ,
1195
+ ty:: Tuple ( fs) => Fields :: wildcards_from_tys ( pcx. cx , fs. iter ( ) , pcx . span ) ,
1196
+ ty:: Ref ( _, rty, _) => Fields :: wildcards_from_tys ( pcx. cx , once ( * rty) , pcx . span ) ,
1196
1197
ty:: Adt ( adt, substs) => {
1197
1198
if adt. is_box ( ) {
1198
1199
// The only legal patterns of type `Box` (outside `std`) are `_` and box
1199
1200
// patterns. If we're here we can assume this is a box pattern.
1200
- Fields :: wildcards_from_tys ( pcx. cx , once ( substs. type_at ( 0 ) ) )
1201
+ Fields :: wildcards_from_tys ( pcx. cx , once ( substs. type_at ( 0 ) ) , pcx . span )
1201
1202
} else {
1202
1203
let variant = & adt. variant ( constructor. variant_index_for_adt ( * adt) ) ;
1203
1204
let tys = Fields :: list_variant_nonhidden_fields ( pcx. cx , pcx. ty , variant)
1204
1205
. map ( |( _, ty) | ty) ;
1205
- Fields :: wildcards_from_tys ( pcx. cx , tys)
1206
+ Fields :: wildcards_from_tys ( pcx. cx , tys, pcx . span )
1206
1207
}
1207
1208
}
1208
1209
_ => bug ! ( "Unexpected type for `Single` constructor: {:?}" , pcx) ,
1209
1210
} ,
1210
1211
Slice ( slice) => match * pcx. ty . kind ( ) {
1211
1212
ty:: Slice ( ty) | ty:: Array ( ty, _) => {
1212
1213
let arity = slice. arity ( ) ;
1213
- Fields :: wildcards_from_tys ( pcx. cx , ( 0 ..arity) . map ( |_| ty) )
1214
+ Fields :: wildcards_from_tys ( pcx. cx , ( 0 ..arity) . map ( |_| ty) , pcx . span )
1214
1215
}
1215
1216
_ => bug ! ( "bad slice pattern {:?} {:?}" , constructor, pcx) ,
1216
1217
} ,
@@ -1251,8 +1252,8 @@ pub(crate) struct DeconstructedPat<'p, 'tcx> {
1251
1252
}
1252
1253
1253
1254
impl < ' p , ' tcx > DeconstructedPat < ' p , ' tcx > {
1254
- pub ( super ) fn wildcard ( ty : Ty < ' tcx > ) -> Self {
1255
- Self :: new ( Wildcard , Fields :: empty ( ) , ty, DUMMY_SP )
1255
+ pub ( super ) fn wildcard ( ty : Ty < ' tcx > , span : Span ) -> Self {
1256
+ Self :: new ( Wildcard , Fields :: empty ( ) , ty, span )
1256
1257
}
1257
1258
1258
1259
pub ( super ) fn new (
@@ -1269,7 +1270,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
1269
1270
/// `Some(_)`.
1270
1271
pub ( super ) fn wild_from_ctor ( pcx : & PatCtxt < ' _ , ' p , ' tcx > , ctor : Constructor < ' tcx > ) -> Self {
1271
1272
let fields = Fields :: wildcards ( pcx, & ctor) ;
1272
- DeconstructedPat :: new ( ctor, fields, pcx. ty , DUMMY_SP )
1273
+ DeconstructedPat :: new ( ctor, fields, pcx. ty , pcx . span )
1273
1274
}
1274
1275
1275
1276
/// Clone this value. This method emphasizes that cloning loses reachability information and
@@ -1298,7 +1299,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
1298
1299
ty:: Tuple ( fs) => {
1299
1300
ctor = Single ;
1300
1301
let mut wilds: SmallVec < [ _ ; 2 ] > =
1301
- fs. iter ( ) . map ( DeconstructedPat :: wildcard) . collect ( ) ;
1302
+ fs. iter ( ) . map ( |ty| DeconstructedPat :: wildcard ( ty , pat . span ) ) . collect ( ) ;
1302
1303
for pat in subpatterns {
1303
1304
wilds[ pat. field . index ( ) ] = mkpat ( & pat. pattern ) ;
1304
1305
}
@@ -1317,11 +1318,11 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
1317
1318
// normally or through box-patterns. We'll have to figure out a proper
1318
1319
// solution when we introduce generalized deref patterns. Also need to
1319
1320
// prevent mixing of those two options.
1320
- let pat = subpatterns. into_iter ( ) . find ( |pat| pat. field . index ( ) == 0 ) ;
1321
- let pat = if let Some ( pat) = pat {
1321
+ let pattern = subpatterns. into_iter ( ) . find ( |pat| pat. field . index ( ) == 0 ) ;
1322
+ let pat = if let Some ( pat) = pattern {
1322
1323
mkpat ( & pat. pattern )
1323
1324
} else {
1324
- DeconstructedPat :: wildcard ( substs. type_at ( 0 ) )
1325
+ DeconstructedPat :: wildcard ( substs. type_at ( 0 ) , pat . span )
1325
1326
} ;
1326
1327
ctor = Single ;
1327
1328
fields = Fields :: singleton ( cx, pat) ;
@@ -1343,7 +1344,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
1343
1344
ty
1344
1345
} ) ;
1345
1346
let mut wilds: SmallVec < [ _ ; 2 ] > =
1346
- tys. map ( DeconstructedPat :: wildcard) . collect ( ) ;
1347
+ tys. map ( |ty| DeconstructedPat :: wildcard ( ty , pat . span ) ) . collect ( ) ;
1347
1348
for pat in subpatterns {
1348
1349
if let Some ( i) = field_id_to_id[ pat. field . index ( ) ] {
1349
1350
wilds[ i] = mkpat ( & pat. pattern ) ;
@@ -1566,8 +1567,10 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
1566
1567
} ;
1567
1568
let prefix = & self . fields . fields [ ..prefix] ;
1568
1569
let suffix = & self . fields . fields [ self_slice. arity ( ) - suffix..] ;
1569
- let wildcard: & _ =
1570
- pcx. cx . pattern_arena . alloc ( DeconstructedPat :: wildcard ( inner_ty) ) ;
1570
+ let wildcard: & _ = pcx
1571
+ . cx
1572
+ . pattern_arena
1573
+ . alloc ( DeconstructedPat :: wildcard ( inner_ty, pcx. span ) ) ;
1571
1574
let extra_wildcards = other_slice. arity ( ) - self_slice. arity ( ) ;
1572
1575
let extra_wildcards = ( 0 ..extra_wildcards) . map ( |_| wildcard) ;
1573
1576
prefix. iter ( ) . chain ( extra_wildcards) . chain ( suffix) . collect ( )
0 commit comments