@@ -246,6 +246,18 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
246
246
} )
247
247
}
248
248
249
+ fn field_pats (
250
+ & self ,
251
+ vals : impl Iterator < Item = & ' tcx ty:: Const < ' tcx > > ,
252
+ ) -> Result < Vec < FieldPat < ' tcx > > , FallbackToConstRef > {
253
+ vals. enumerate ( )
254
+ . map ( |( idx, val) | {
255
+ let field = Field :: new ( idx) ;
256
+ Ok ( FieldPat { field, pattern : self . recur ( val, false ) ? } )
257
+ } )
258
+ . collect ( )
259
+ }
260
+
249
261
// Recursive helper for `to_pat`; invoke that (instead of calling this directly).
250
262
fn recur (
251
263
& self ,
@@ -257,16 +269,6 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
257
269
let tcx = self . tcx ( ) ;
258
270
let param_env = self . param_env ;
259
271
260
- let field_pats = |vals : & [ & ' tcx ty:: Const < ' tcx > ] | -> Result < _ , _ > {
261
- vals. iter ( )
262
- . enumerate ( )
263
- . map ( |( idx, val) | {
264
- let field = Field :: new ( idx) ;
265
- Ok ( FieldPat { field, pattern : self . recur ( val, false ) ? } )
266
- } )
267
- . collect ( )
268
- } ;
269
-
270
272
let kind = match cv. ty . kind ( ) {
271
273
ty:: Float ( _) => {
272
274
tcx. struct_span_lint_hir (
@@ -361,12 +363,12 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
361
363
variant_index : destructured
362
364
. variant
363
365
. expect ( "destructed const of adt without variant id" ) ,
364
- subpatterns : field_pats ( destructured. fields ) ?,
366
+ subpatterns : self . field_pats ( destructured. fields . iter ( ) . copied ( ) ) ?,
365
367
}
366
368
}
367
369
ty:: Tuple ( _) | ty:: Adt ( _, _) => {
368
370
let destructured = tcx. destructure_const ( param_env. and ( cv) ) ;
369
- PatKind :: Leaf { subpatterns : field_pats ( destructured. fields ) ? }
371
+ PatKind :: Leaf { subpatterns : self . field_pats ( destructured. fields . iter ( ) . copied ( ) ) ? }
370
372
}
371
373
ty:: Array ( ..) => PatKind :: Array {
372
374
prefix : tcx
0 commit comments