Skip to content

Commit 13f8b3f

Browse files
committed
Handle conditionals on _|_ - typed values correctly
Closes rust-lang#776
1 parent 7c34550 commit 13f8b3f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/comp/middle/trans.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3592,6 +3592,18 @@ fn trans_if(cx: &@block_ctxt, cond: &@ast::expr, thn: &ast::blk,
35923592
els: &option::t[@ast::expr], id: ast::node_id,
35933593
output: &out_method) -> result {
35943594
let cond_res = trans_expr(cx, cond);
3595+
3596+
if (ty::type_is_bot(bcx_tcx(cx), ty::expr_ty(bcx_tcx(cx), cond))) {
3597+
// No need to generate code for comparison,
3598+
// since the cond diverges.
3599+
if (!cx.build.is_terminated()) {
3600+
ret rslt(cx, cx.build.Unreachable());
3601+
}
3602+
else {
3603+
ret rslt(cx, C_nil());
3604+
}
3605+
}
3606+
35953607
let then_cx = new_scope_block_ctxt(cx, "then");
35963608
let then_res = trans_block(then_cx, thn, output);
35973609
let else_cx = new_scope_block_ctxt(cx, "else");

src/test/run-fail/if-cond-bot.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// error-pattern:quux
2+
fn my_err(s: str) -> ! { log_err s; fail "quux"; }
3+
fn main() { if my_err("bye") { } }

0 commit comments

Comments
 (0)