@@ -337,8 +337,8 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
337
337
return ;
338
338
}
339
339
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 ( ) {
342
342
let var_name = maps. tcx . hir ( ) . name ( var_hir_id) ;
343
343
maps. add_variable ( Upvar ( var_hir_id, var_name) ) ;
344
344
}
@@ -405,21 +405,14 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
405
405
// breaks or continues)
406
406
self . add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span , expr. hir_id ) ) ;
407
407
408
- // Make a live_node for each captured variable, with the span
408
+ // Make a live_node for each mentioned variable, with the span
409
409
// being the location that the variable is used. This results
410
410
// in better error messages than just pointing at the closure
411
411
// construction site.
412
412
let mut call_caps = Vec :: new ( ) ;
413
413
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| {
423
416
let upvar = upvars[ var_id] ;
424
417
let upvar_ln = self . add_live_node ( UpvarNode ( upvar. span ) ) ;
425
418
CaptureInfo { ln : upvar_ln, var_hid : * var_id }
@@ -494,7 +487,6 @@ struct Liveness<'a, 'tcx> {
494
487
ir : & ' a mut IrMaps < ' tcx > ,
495
488
typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
496
489
param_env : ty:: ParamEnv < ' tcx > ,
497
- upvars : Option < & ' tcx FxIndexMap < hir:: HirId , hir:: Upvar > > ,
498
490
closure_min_captures : Option < & ' tcx RootVariableMinCaptureList < ' tcx > > ,
499
491
successors : IndexVec < LiveNode , Option < LiveNode > > ,
500
492
rwu_table : rwu_table:: RWUTable ,
@@ -518,7 +510,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
518
510
fn new ( ir : & ' a mut IrMaps < ' tcx > , body_owner : LocalDefId ) -> Liveness < ' a , ' tcx > {
519
511
let typeck_results = ir. tcx . typeck ( body_owner) ;
520
512
let param_env = ir. tcx . param_env ( body_owner) ;
521
- let upvars = ir. tcx . upvars_mentioned ( body_owner) ;
522
513
let closure_min_captures = typeck_results. closure_min_captures . get ( & body_owner. to_def_id ( ) ) ;
523
514
let closure_ln = ir. add_live_node ( ClosureNode ) ;
524
515
let exit_ln = ir. add_live_node ( ExitNode ) ;
@@ -530,7 +521,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
530
521
ir,
531
522
typeck_results,
532
523
param_env,
533
- upvars,
534
524
closure_min_captures,
535
525
successors : IndexVec :: from_elem_n ( None , num_live_nodes) ,
536
526
rwu_table : rwu_table:: RWUTable :: new ( num_live_nodes, num_vars) ,
@@ -1215,21 +1205,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
1215
1205
acc : u32 ,
1216
1206
) -> LiveNode {
1217
1207
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 ) ,
1233
1209
_ => succ,
1234
1210
}
1235
1211
}
0 commit comments