@@ -131,8 +131,8 @@ enum LoopKind<'a> {
131
131
LoopLoop ,
132
132
/// A `while` loop, with the given expression as condition.
133
133
WhileLoop ( & ' a Expr ) ,
134
- /// A `for` loop.
135
- ForLoop ,
134
+ /// A `for` loop, with the given pattern to bind .
135
+ ForLoop ( & ' a Pat ) ,
136
136
}
137
137
138
138
#[ deriving( PartialEq ) ]
@@ -1024,8 +1024,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
1024
1024
self . propagate_through_loop ( expr, WhileLoop ( & * * cond) , & * * blk, succ)
1025
1025
}
1026
1026
1027
- ExprForLoop ( _ , ref head, ref blk, _) => {
1028
- let ln = self . propagate_through_loop ( expr, ForLoop , & * * blk, succ) ;
1027
+ ExprForLoop ( ref pat , ref head, ref blk, _) => {
1028
+ let ln = self . propagate_through_loop ( expr, ForLoop ( & * * pat ) , & * * blk, succ) ;
1029
1029
self . propagate_through_expr ( & * * head, ln)
1030
1030
}
1031
1031
@@ -1355,7 +1355,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
1355
1355
expr. id, block_to_string( body) ) ;
1356
1356
1357
1357
let cond_ln = match kind {
1358
- LoopLoop | ForLoop => ln,
1358
+ LoopLoop => ln,
1359
+ ForLoop ( ref pat) => self . define_bindings_in_pat ( * pat, ln) ,
1359
1360
WhileLoop ( ref cond) => self . propagate_through_expr ( & * * cond, ln) ,
1360
1361
} ;
1361
1362
let body_ln = self . with_loop_nodes ( expr. id , succ, ln, |this| {
@@ -1367,7 +1368,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
1367
1368
first_merge = false ;
1368
1369
1369
1370
let new_cond_ln = match kind {
1370
- LoopLoop | ForLoop => ln,
1371
+ LoopLoop => ln,
1372
+ ForLoop ( ref pat) => {
1373
+ self . define_bindings_in_pat ( * pat, ln)
1374
+ }
1371
1375
WhileLoop ( ref cond) => {
1372
1376
self . propagate_through_expr ( & * * cond, ln)
1373
1377
}
@@ -1453,6 +1457,12 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
1453
1457
visit:: walk_expr ( this, expr) ;
1454
1458
}
1455
1459
1460
+ ExprForLoop ( ref pat, _, _, _) => {
1461
+ this. pat_bindings ( & * * pat, |this, ln, var, sp, id| {
1462
+ this. warn_about_unused ( sp, id, ln, var) ;
1463
+ } ) ;
1464
+ }
1465
+
1456
1466
// no correctness conditions related to liveness
1457
1467
ExprCall ( ..) | ExprMethodCall ( ..) | ExprIf ( ..) | ExprMatch ( ..) |
1458
1468
ExprWhile ( ..) | ExprLoop ( ..) | ExprIndex ( ..) | ExprField ( ..) |
@@ -1461,7 +1471,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
1461
1471
ExprAgain ( ..) | ExprLit ( _) | ExprBlock ( ..) |
1462
1472
ExprMac ( ..) | ExprAddrOf ( ..) | ExprStruct ( ..) | ExprRepeat ( ..) |
1463
1473
ExprParen ( ..) | ExprFnBlock ( ..) | ExprProc ( ..) | ExprUnboxedFn ( ..) |
1464
- ExprPath ( ..) | ExprBox ( ..) | ExprForLoop ( .. ) => {
1474
+ ExprPath ( ..) | ExprBox ( ..) => {
1465
1475
visit:: walk_expr ( this, expr) ;
1466
1476
}
1467
1477
}
0 commit comments