about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-08-23 14:51:22 -0700
committerBrian Anderson <banderson@mozilla.com>2011-08-23 14:51:22 -0700
commita3c8d4a5a58b42db6b8795980992e1063e84f59f (patch)
treeb1222e51fd0cd3375b401bdafbb4a7c94b9649b2
parent68fd28c2c139109bac3372c5fe6d05b228d6a579 (diff)
downloadrust-a3c8d4a5a58b42db6b8795980992e1063e84f59f.tar.gz
rust-a3c8d4a5a58b42db6b8795980992e1063e84f59f.zip
Recheck the while loop contition after continuing. Closes #825
-rw-r--r--src/comp/middle/trans.rs8
-rw-r--r--src/test/run-pass/while-cont.rs10
2 files changed, 14 insertions, 4 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 309be3fd2db..5a6791c5b85 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -3188,11 +3188,11 @@ fn trans_for_each(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
 
 fn trans_while(cx: &@block_ctxt, cond: &@ast::expr, body: &ast::blk) ->
    result {
-    let cond_cx = new_scope_block_ctxt(cx, "while cond");
-    let next_cx = new_sub_block_ctxt(cx, "next");
+    let next_cx = new_sub_block_ctxt(cx, "while next");
+    let cond_cx = new_loop_scope_block_ctxt(cx, option::none::<@block_ctxt>,
+                                            next_cx, "while cond");
     let body_cx =
-        new_loop_scope_block_ctxt(cx, option::none::<@block_ctxt>, next_cx,
-                                  "while loop body");
+        new_scope_block_ctxt(cond_cx, "while loop body");
     let body_res = trans_block(body_cx, body, return);
     let cond_res = trans_expr(cond_cx, cond);
     body_res.bcx.build.Br(cond_cx.llbb);
diff --git a/src/test/run-pass/while-cont.rs b/src/test/run-pass/while-cont.rs
new file mode 100644
index 00000000000..78c4163c3bd
--- /dev/null
+++ b/src/test/run-pass/while-cont.rs
@@ -0,0 +1,10 @@
+// Issue #825: Should recheck the loop contition after continuing
+fn main() {
+    let i = 1;
+    while i > 0 {
+        assert i > 0;
+        log i;
+        i -= 1;
+        cont;
+    }
+}
\ No newline at end of file