Skip to content

Commit a793b85

Browse files
committed
Handle fail inside a for-each loop properly
1 parent ded9008 commit a793b85

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/comp/middle/trans.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4564,7 +4564,11 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
45644564
auto lltop = bcx.llbb;
45654565
auto r = trans_block(bcx, body, return);
45664566
finish_fn(fcx, lltop);
4567-
r.bcx.build.RetVoid();
4567+
4568+
if (!r.bcx.build.is_terminated()) {
4569+
// if terminated is true, no need for the ret-fail
4570+
r.bcx.build.RetVoid();
4571+
}
45684572

45694573
// Step 3: Call iter passing [lliterbody, llenv], plus other args.
45704574
alt (seq.node) {

src/test/run-fail/fail-main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// xfail-stage0
2+
// error-pattern:moop
3+
use std;
4+
import std::uint;
5+
fn main() {
6+
fail "moop";
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// xfail-stage0
2+
// error-pattern:moop
3+
use std;
4+
import std::uint;
5+
fn main() {
6+
for each (uint i in uint::range(0u, 10u)) {
7+
fail "moop";
8+
}
9+
}

src/test/run-pass/for-loop-fail.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// xfail-stage0
2+
fn main() {
3+
let vec[int] x = [];
4+
for (int i in x) {
5+
fail "moop";
6+
}
7+
}

0 commit comments

Comments
 (0)