@@ -246,6 +246,18 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
246246 } )
247247 }
248248
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+
249261 // Recursive helper for `to_pat`; invoke that (instead of calling this directly).
250262 fn recur (
251263 & self ,
@@ -257,16 +269,6 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
257269 let tcx = self . tcx ( ) ;
258270 let param_env = self . param_env ;
259271
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-
270272 let kind = match cv. ty . kind ( ) {
271273 ty:: Float ( _) => {
272274 tcx. struct_span_lint_hir (
@@ -361,12 +363,12 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
361363 variant_index : destructured
362364 . variant
363365 . expect ( "destructed const of adt without variant id" ) ,
364- subpatterns : field_pats ( destructured. fields ) ?,
366+ subpatterns : self . field_pats ( destructured. fields . iter ( ) . copied ( ) ) ?,
365367 }
366368 }
367369 ty:: Tuple ( _) | ty:: Adt ( _, _) => {
368370 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 ( ) ) ? }
370372 }
371373 ty:: Array ( ..) => PatKind :: Array {
372374 prefix : tcx
0 commit comments