@@ -337,8 +337,8 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
337337 return ;
338338 }
339339
340- if let Some ( captures ) = maps. tcx . typeck ( local_def_id ) . closure_min_captures . get ( & def_id) {
341- for & var_hir_id in captures . keys ( ) {
340+ if let Some ( upvars ) = maps. tcx . upvars_mentioned ( def_id) {
341+ for & var_hir_id in upvars . keys ( ) {
342342 let var_name = maps. tcx . hir ( ) . name ( var_hir_id) ;
343343 maps. add_variable ( Upvar ( var_hir_id, var_name) ) ;
344344 }
@@ -405,21 +405,14 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
405405 // breaks or continues)
406406 self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr. hir_id ) ) ;
407407
408- // Make a live_node for each captured variable, with the span
408+ // Make a live_node for each mentioned variable, with the span
409409 // being the location that the variable is used. This results
410410 // in better error messages than just pointing at the closure
411411 // construction site.
412412 let mut call_caps = Vec :: new ( ) ;
413413 let closure_def_id = self . tcx . hir ( ) . local_def_id ( expr. hir_id ) ;
414- if let Some ( captures) = self
415- . tcx
416- . typeck ( closure_def_id)
417- . closure_min_captures
418- . get ( & closure_def_id. to_def_id ( ) )
419- {
420- // If closure_min_captures is Some, upvars_mentioned must also be Some
421- let upvars = self . tcx . upvars_mentioned ( closure_def_id) . unwrap ( ) ;
422- call_caps. extend ( captures. keys ( ) . map ( |var_id| {
414+ if let Some ( upvars) = self . tcx . upvars_mentioned ( closure_def_id) {
415+ call_caps. extend ( upvars. keys ( ) . map ( |var_id| {
423416 let upvar = upvars[ var_id] ;
424417 let upvar_ln = self . add_live_node ( UpvarNode ( upvar. span ) ) ;
425418 CaptureInfo { ln : upvar_ln, var_hid : * var_id }
@@ -494,7 +487,6 @@ struct Liveness<'a, 'tcx> {
494487 ir : & ' a mut IrMaps < ' tcx > ,
495488 typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
496489 param_env : ty:: ParamEnv < ' tcx > ,
497- upvars : Option < & ' tcx FxIndexMap < hir:: HirId , hir:: Upvar > > ,
498490 closure_min_captures : Option < & ' tcx RootVariableMinCaptureList < ' tcx > > ,
499491 successors : IndexVec < LiveNode , Option < LiveNode > > ,
500492 rwu_table : rwu_table:: RWUTable ,
@@ -518,7 +510,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
518510 fn new ( ir : & ' a mut IrMaps < ' tcx > , body_owner : LocalDefId ) -> Liveness < ' a , ' tcx > {
519511 let typeck_results = ir. tcx . typeck ( body_owner) ;
520512 let param_env = ir. tcx . param_env ( body_owner) ;
521- let upvars = ir. tcx . upvars_mentioned ( body_owner) ;
522513 let closure_min_captures = typeck_results. closure_min_captures . get ( & body_owner. to_def_id ( ) ) ;
523514 let closure_ln = ir. add_live_node ( ClosureNode ) ;
524515 let exit_ln = ir. add_live_node ( ExitNode ) ;
@@ -530,7 +521,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
530521 ir,
531522 typeck_results,
532523 param_env,
533- upvars,
534524 closure_min_captures,
535525 successors : IndexVec :: from_elem_n ( None , num_live_nodes) ,
536526 rwu_table : rwu_table:: RWUTable :: new ( num_live_nodes, num_vars) ,
@@ -1215,21 +1205,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
12151205 acc : u32 ,
12161206 ) -> LiveNode {
12171207 match path. res {
1218- Res :: Local ( hid) => {
1219- let in_upvars = self . upvars . map_or ( false , |u| u. contains_key ( & hid) ) ;
1220- let in_captures = self . closure_min_captures . map_or ( false , |c| c. contains_key ( & hid) ) ;
1221-
1222- match ( in_upvars, in_captures) {
1223- ( false , _) | ( true , true ) => self . access_var ( hir_id, hid, succ, acc, path. span ) ,
1224- ( true , false ) => {
1225- // This case is possible when with RFC-2229, a wild pattern
1226- // is used within a closure.
1227- // eg: `let _ = x`. The closure doesn't capture x here,
1228- // even though it's mentioned in the closure.
1229- succ
1230- }
1231- }
1232- }
1208+ Res :: Local ( hid) => self . access_var ( hir_id, hid, succ, acc, path. span ) ,
12331209 _ => succ,
12341210 }
12351211 }
0 commit comments