@@ -474,8 +474,11 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
474
474
// live nodes required for uses or definitions of variables:
475
475
hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) => {
476
476
debug ! ( "expr {}: path that leads to {:?}" , expr. hir_id, path. res) ;
477
- if let Res :: Local ( ..) = path. res {
478
- ir. add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
477
+ if let Res :: Local ( var_hir_id) = path. res {
478
+ let upvars = ir. tcx . upvars ( ir. body_owner ) ;
479
+ if !upvars. map_or ( false , |upvars| upvars. contains_key ( & var_hir_id) ) {
480
+ ir. add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
481
+ }
479
482
}
480
483
intravisit:: walk_expr ( ir, expr) ;
481
484
}
@@ -1338,8 +1341,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
1338
1341
-> LiveNode {
1339
1342
match path. res {
1340
1343
Res :: Local ( hid) => {
1341
- let nid = self . ir . tcx . hir ( ) . hir_to_node_id ( hid) ;
1342
- self . access_var ( hir_id, nid, succ, acc, path. span )
1344
+ let upvars = self . ir . tcx . upvars ( self . ir . body_owner ) ;
1345
+ if !upvars. map_or ( false , |upvars| upvars. contains_key ( & hid) ) {
1346
+ let nid = self . ir . tcx . hir ( ) . hir_to_node_id ( hid) ;
1347
+ self . access_var ( hir_id, nid, succ, acc, path. span )
1348
+ } else {
1349
+ succ
1350
+ }
1343
1351
}
1344
1352
_ => succ
1345
1353
}
@@ -1531,13 +1539,16 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
1531
1539
match expr. node {
1532
1540
hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) => {
1533
1541
if let Res :: Local ( var_hid) = path. res {
1534
- // Assignment to an immutable variable or argument: only legal
1535
- // if there is no later assignment. If this local is actually
1536
- // mutable, then check for a reassignment to flag the mutability
1537
- // as being used.
1538
- let ln = self . live_node ( expr. hir_id , expr. span ) ;
1539
- let var = self . variable ( var_hid, expr. span ) ;
1540
- self . warn_about_dead_assign ( expr. span , expr. hir_id , ln, var) ;
1542
+ let upvars = self . ir . tcx . upvars ( self . ir . body_owner ) ;
1543
+ if !upvars. map_or ( false , |upvars| upvars. contains_key ( & var_hid) ) {
1544
+ // Assignment to an immutable variable or argument: only legal
1545
+ // if there is no later assignment. If this local is actually
1546
+ // mutable, then check for a reassignment to flag the mutability
1547
+ // as being used.
1548
+ let ln = self . live_node ( expr. hir_id , expr. span ) ;
1549
+ let var = self . variable ( var_hid, expr. span ) ;
1550
+ self . warn_about_dead_assign ( expr. span , expr. hir_id , ln, var) ;
1551
+ }
1541
1552
}
1542
1553
}
1543
1554
_ => {
0 commit comments