@@ -647,42 +647,46 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
647
647
let fn_def_id = tcx_hir. local_def_id ( fn_id) ;
648
648
649
649
// Gather the upvars of a closure, if any.
650
- let upvar_decls: Vec < _ > = match hir_tables. upvar_list . get ( & fn_def_id) {
651
- Some ( upvars) => upvars
652
- . iter ( )
653
- . map ( |upvar_id| {
654
- let var_hir_id = upvar_id. var_path . hir_id ;
655
- let var_node_id = tcx_hir. hir_to_node_id ( var_hir_id) ;
656
- let capture = hir_tables. upvar_capture ( * upvar_id) ;
657
- let by_ref = match capture {
658
- ty:: UpvarCapture :: ByValue => false ,
659
- ty:: UpvarCapture :: ByRef ( ..) => true ,
660
- } ;
661
- let mut decl = UpvarDecl {
662
- debug_name : keywords:: Invalid . name ( ) ,
663
- var_hir_id : ClearCrossCrate :: Set ( var_hir_id) ,
664
- by_ref,
665
- mutability : Mutability :: Not ,
666
- } ;
667
- if let Some ( Node :: Binding ( pat) ) = tcx_hir. find ( var_node_id) {
668
- if let hir:: PatKind :: Binding ( _, _, ident, _) = pat. node {
669
- decl. debug_name = ident. name ;
670
- if let Some ( & bm) = hir. tables . pat_binding_modes ( ) . get ( pat. hir_id ) {
671
- if bm == ty:: BindByValue ( hir:: MutMutable ) {
672
- decl. mutability = Mutability :: Mut ;
673
- } else {
674
- decl. mutability = Mutability :: Not ;
675
- }
650
+ // In analyze_closure() in upvar.rs we gathered a list of upvars used by a
651
+ // closure and we stored in a map called upvar_list in TypeckTables indexed
652
+ // with the closure's DefId. Here, we run through that vec of UpvarIds for
653
+ // the given closure and use the necessary information to create UpvarDecl.
654
+ let upvar_decls: Vec < _ > = hir_tables
655
+ . upvar_list
656
+ . get ( & fn_def_id)
657
+ . into_iter ( )
658
+ . flatten ( )
659
+ . map ( |upvar_id| {
660
+ let var_hir_id = upvar_id. var_path . hir_id ;
661
+ let var_node_id = tcx_hir. hir_to_node_id ( var_hir_id) ;
662
+ let capture = hir_tables. upvar_capture ( * upvar_id) ;
663
+ let by_ref = match capture {
664
+ ty:: UpvarCapture :: ByValue => false ,
665
+ ty:: UpvarCapture :: ByRef ( ..) => true ,
666
+ } ;
667
+ let mut decl = UpvarDecl {
668
+ debug_name : keywords:: Invalid . name ( ) ,
669
+ var_hir_id : ClearCrossCrate :: Set ( var_hir_id) ,
670
+ by_ref,
671
+ mutability : Mutability :: Not ,
672
+ } ;
673
+ if let Some ( Node :: Binding ( pat) ) = tcx_hir. find ( var_node_id) {
674
+ if let hir:: PatKind :: Binding ( _, _, ident, _) = pat. node {
675
+ decl. debug_name = ident. name ;
676
+ if let Some ( & bm) = hir. tables . pat_binding_modes ( ) . get ( pat. hir_id ) {
677
+ if bm == ty:: BindByValue ( hir:: MutMutable ) {
678
+ decl. mutability = Mutability :: Mut ;
676
679
} else {
677
- tcx . sess . delay_span_bug ( pat . span , "missing binding mode" ) ;
680
+ decl . mutability = Mutability :: Not ;
678
681
}
682
+ } else {
683
+ tcx. sess . delay_span_bug ( pat. span , "missing binding mode" ) ;
679
684
}
680
685
}
681
- decl
682
- } )
683
- . collect ( ) ,
684
- _ => vec ! [ ] ,
685
- } ;
686
+ }
687
+ decl
688
+ } )
689
+ . collect ( ) ;
686
690
687
691
let mut builder = Builder :: new ( hir,
688
692
span,
0 commit comments