@@ -4,7 +4,7 @@ use hair::cx::Cx;
44use hair:: { LintLevel , BindingMode , PatternKind } ;
55use rustc:: hir;
66use rustc:: hir:: Node ;
7- use rustc:: hir:: def_id:: { DefId , LocalDefId } ;
7+ use rustc:: hir:: def_id:: DefId ;
88use rustc:: middle:: region;
99use rustc:: mir:: * ;
1010use rustc:: mir:: visit:: { MutVisitor , TyContext } ;
@@ -640,47 +640,49 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
640640 let arguments: Vec < _ > = arguments. collect ( ) ;
641641
642642 let tcx = hir. tcx ( ) ;
643- let span = tcx. hir ( ) . span ( fn_id) ;
643+ let tcx_hir = tcx. hir ( ) ;
644+ let span = tcx_hir. span ( fn_id) ;
644645
645- // hir.tables().upvar_list[fn_id].
646- // Gather the upvars of a closure, if any.
647- let upvar_decls: Vec < _ > = tcx. with_freevars ( fn_id, |freevars| {
648- freevars. iter ( ) . map ( |fv| {
649- let var_id = fv. var_id ( ) ;
650- let var_hir_id = tcx. hir ( ) . node_to_hir_id ( var_id) ;
651- let closure_expr_id = tcx. hir ( ) . local_def_id ( fn_id) ;
652- let capture = hir. tables ( ) . upvar_capture ( ty:: UpvarId {
653- var_path : ty:: UpvarPath { hir_id : var_hir_id} ,
654- closure_expr_id : LocalDefId :: from_def_id ( closure_expr_id) ,
655- } ) ;
656- let by_ref = match capture {
657- ty:: UpvarCapture :: ByValue => false ,
658- ty:: UpvarCapture :: ByRef ( ..) => true
659- } ;
660- let mut decl = UpvarDecl {
661- debug_name : keywords:: Invalid . name ( ) ,
662- var_hir_id : ClearCrossCrate :: Set ( var_hir_id) ,
663- by_ref,
664- mutability : Mutability :: Not ,
665- } ;
666- if let Some ( Node :: Binding ( pat) ) = tcx. hir ( ) . find ( var_id) {
667- if let hir:: PatKind :: Binding ( _, _, ident, _) = pat. node {
668- decl. debug_name = ident. name ;
646+ let hir_tables = hir. tables ( ) ;
647+ let fn_def_id = tcx_hir. local_def_id ( fn_id) ;
669648
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 ;
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+ }
673676 } else {
674- decl . mutability = Mutability :: Not ;
677+ tcx . sess . delay_span_bug ( pat . span , "missing binding mode" ) ;
675678 }
676- } else {
677- tcx. sess . delay_span_bug ( pat. span , "missing binding mode" ) ;
678679 }
679680 }
680- }
681- decl
682- } ) . collect ( )
683- } ) ;
681+ decl
682+ } )
683+ . collect ( ) ,
684+ _ => vec ! [ ] ,
685+ } ;
684686
685687 let mut builder = Builder :: new ( hir,
686688 span,
@@ -690,7 +692,6 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
690692 return_ty_span,
691693 upvar_decls) ;
692694
693- let fn_def_id = tcx. hir ( ) . local_def_id ( fn_id) ;
694695 let call_site_scope = region:: Scope {
695696 id : body. value . hir_id . local_id ,
696697 data : region:: ScopeData :: CallSite
@@ -733,7 +734,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
733734 // RustCall pseudo-ABI untuples the last argument.
734735 spread_arg = Some ( Local :: new ( arguments. len ( ) ) ) ;
735736 }
736- let closure_expr_id = tcx . hir ( ) . local_def_id ( fn_id) ;
737+ let closure_expr_id = tcx_hir . local_def_id ( fn_id) ;
737738 info ! ( "fn_id {:?} has attrs {:?}" , closure_expr_id,
738739 tcx. get_attrs( closure_expr_id) ) ;
739740
0 commit comments