@@ -474,8 +474,11 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
474474 // live nodes required for uses or definitions of variables:
475475 hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) => {
476476 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+ }
479482 }
480483 intravisit:: walk_expr ( ir, expr) ;
481484 }
@@ -1338,8 +1341,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
13381341 -> LiveNode {
13391342 match path. res {
13401343 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+ }
13431351 }
13441352 _ => succ
13451353 }
@@ -1531,13 +1539,16 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15311539 match expr. node {
15321540 hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) => {
15331541 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+ }
15411552 }
15421553 }
15431554 _ => {
0 commit comments