@@ -1154,8 +1154,9 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
11541154 fn wildcards_from_tys (
11551155 cx : & MatchCheckCtxt < ' p , ' tcx > ,
11561156 tys : impl IntoIterator < Item = Ty < ' tcx > > ,
1157+ span : Span ,
11571158 ) -> 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 ) ) )
11591160 }
11601161
11611162 // 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> {
11911192 pub ( super ) fn wildcards ( pcx : & PatCtxt < ' _ , ' p , ' tcx > , constructor : & Constructor < ' tcx > ) -> Self {
11921193 let ret = match constructor {
11931194 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 ) ,
11961197 ty:: Adt ( adt, substs) => {
11971198 if adt. is_box ( ) {
11981199 // The only legal patterns of type `Box` (outside `std`) are `_` and box
11991200 // 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 )
12011202 } else {
12021203 let variant = & adt. variant ( constructor. variant_index_for_adt ( * adt) ) ;
12031204 let tys = Fields :: list_variant_nonhidden_fields ( pcx. cx , pcx. ty , variant)
12041205 . map ( |( _, ty) | ty) ;
1205- Fields :: wildcards_from_tys ( pcx. cx , tys)
1206+ Fields :: wildcards_from_tys ( pcx. cx , tys, pcx . span )
12061207 }
12071208 }
12081209 _ => bug ! ( "Unexpected type for `Single` constructor: {:?}" , pcx) ,
12091210 } ,
12101211 Slice ( slice) => match * pcx. ty . kind ( ) {
12111212 ty:: Slice ( ty) | ty:: Array ( ty, _) => {
12121213 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 )
12141215 }
12151216 _ => bug ! ( "bad slice pattern {:?} {:?}" , constructor, pcx) ,
12161217 } ,
@@ -1251,8 +1252,8 @@ pub(crate) struct DeconstructedPat<'p, 'tcx> {
12511252}
12521253
12531254impl < ' 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 )
12561257 }
12571258
12581259 pub ( super ) fn new (
@@ -1269,7 +1270,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
12691270 /// `Some(_)`.
12701271 pub ( super ) fn wild_from_ctor ( pcx : & PatCtxt < ' _ , ' p , ' tcx > , ctor : Constructor < ' tcx > ) -> Self {
12711272 let fields = Fields :: wildcards ( pcx, & ctor) ;
1272- DeconstructedPat :: new ( ctor, fields, pcx. ty , DUMMY_SP )
1273+ DeconstructedPat :: new ( ctor, fields, pcx. ty , pcx . span )
12731274 }
12741275
12751276 /// Clone this value. This method emphasizes that cloning loses reachability information and
@@ -1298,7 +1299,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
12981299 ty:: Tuple ( fs) => {
12991300 ctor = Single ;
13001301 let mut wilds: SmallVec < [ _ ; 2 ] > =
1301- fs. iter ( ) . map ( DeconstructedPat :: wildcard) . collect ( ) ;
1302+ fs. iter ( ) . map ( |ty| DeconstructedPat :: wildcard ( ty , pat . span ) ) . collect ( ) ;
13021303 for pat in subpatterns {
13031304 wilds[ pat. field . index ( ) ] = mkpat ( & pat. pattern ) ;
13041305 }
@@ -1317,11 +1318,11 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
13171318 // normally or through box-patterns. We'll have to figure out a proper
13181319 // solution when we introduce generalized deref patterns. Also need to
13191320 // 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 {
13221323 mkpat ( & pat. pattern )
13231324 } else {
1324- DeconstructedPat :: wildcard ( substs. type_at ( 0 ) )
1325+ DeconstructedPat :: wildcard ( substs. type_at ( 0 ) , pat . span )
13251326 } ;
13261327 ctor = Single ;
13271328 fields = Fields :: singleton ( cx, pat) ;
@@ -1343,7 +1344,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
13431344 ty
13441345 } ) ;
13451346 let mut wilds: SmallVec < [ _ ; 2 ] > =
1346- tys. map ( DeconstructedPat :: wildcard) . collect ( ) ;
1347+ tys. map ( |ty| DeconstructedPat :: wildcard ( ty , pat . span ) ) . collect ( ) ;
13471348 for pat in subpatterns {
13481349 if let Some ( i) = field_id_to_id[ pat. field . index ( ) ] {
13491350 wilds[ i] = mkpat ( & pat. pattern ) ;
@@ -1566,8 +1567,10 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
15661567 } ;
15671568 let prefix = & self . fields . fields [ ..prefix] ;
15681569 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 ) ) ;
15711574 let extra_wildcards = other_slice. arity ( ) - self_slice. arity ( ) ;
15721575 let extra_wildcards = ( 0 ..extra_wildcards) . map ( |_| wildcard) ;
15731576 prefix. iter ( ) . chain ( extra_wildcards) . chain ( suffix) . collect ( )
0 commit comments