Skip to content

Commit 6bae4a7

Browse files
committed
Fix unused_assignments false positive
Make `continue` jump to the loop condition's `LiveNode` instead of one of the loop body.
1 parent 1409363 commit 6bae4a7

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/librustc/middle/liveness.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
911911
}
912912

913913
fn compute(&mut self, body: &hir::Expr) -> LiveNode {
914-
// if there is a `break` or `again` at the top level, then it's
914+
// if there is a `break` or `continue` at the top level, then it's
915915
// effectively a return---this only occurs in `for` loops,
916916
// where the body is really a closure.
917917

@@ -1407,15 +1407,16 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
14071407
debug!("propagate_through_loop: using id for loop body {} {}",
14081408
expr.id, self.ir.tcx.hir().node_to_pretty_string(body.id));
14091409

1410-
let break_ln = succ;
1411-
let cont_ln = ln;
1412-
self.break_ln.insert(expr.id, break_ln);
1413-
self.cont_ln.insert(expr.id, cont_ln);
1410+
1411+
self.break_ln.insert(expr.id, succ);
14141412

14151413
let cond_ln = match kind {
14161414
LoopLoop => ln,
14171415
WhileLoop(ref cond) => self.propagate_through_expr(&cond, ln),
14181416
};
1417+
1418+
self.cont_ln.insert(expr.id, cond_ln);
1419+
14191420
let body_ln = self.propagate_through_block(body, cond_ln);
14201421

14211422
// repeat until fixed point is reached:

src/test/ui/liveness/liveness-dead.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,13 @@ fn f5(mut x: i32) {
2727
x = 4; //~ ERROR: value assigned to `x` is never read
2828
}
2929

30+
// #22630
31+
fn f6() {
32+
let mut done = false;
33+
while !done {
34+
done = true; // no error
35+
continue;
36+
}
37+
}
38+
3039
fn main() {}

0 commit comments

Comments
 (0)