Skip to content

Commit

Permalink
Fix unused_assignments false positive
Browse files Browse the repository at this point in the history
Make `continue` jump to the loop condition's `LiveNode` instead of one
of the loop body.
  • Loading branch information
sinkuu committed Jan 3, 2019
1 parent 1409363 commit 6bae4a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/librustc/middle/liveness.rs
Expand Up @@ -911,7 +911,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}

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

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

let break_ln = succ;
let cont_ln = ln;
self.break_ln.insert(expr.id, break_ln);
self.cont_ln.insert(expr.id, cont_ln);

self.break_ln.insert(expr.id, succ);

let cond_ln = match kind {
LoopLoop => ln,
WhileLoop(ref cond) => self.propagate_through_expr(&cond, ln),
};

self.cont_ln.insert(expr.id, cond_ln);

let body_ln = self.propagate_through_block(body, cond_ln);

// repeat until fixed point is reached:
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/liveness/liveness-dead.rs
Expand Up @@ -27,4 +27,13 @@ fn f5(mut x: i32) {
x = 4; //~ ERROR: value assigned to `x` is never read
}

// #22630
fn f6() {
let mut done = false;
while !done {
done = true; // no error
continue;
}
}

fn main() {}

0 comments on commit 6bae4a7

Please sign in to comment.