Skip to content

Commit e24d7ae

Browse files
committed
rustc: If all if branches are _|_, then the entire if is _|_
1 parent c0b4fc1 commit e24d7ae

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/comp/middle/typeck.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,10 +2144,8 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) {
21442144
if (!ty::type_is_bot(scx.fcx.ccx.tcx, elsopt_t)) {
21452145
Pushdown::pushdown_expr(scx, thn_t, els);
21462146
if_t = elsopt_t;
2147-
} else if (!ty::type_is_bot(scx.fcx.ccx.tcx, thn_t)) {
2148-
if_t = thn_t;
21492147
} else {
2150-
if_t = ty::mk_nil(scx.fcx.ccx.tcx);
2148+
if_t = thn_t;
21512149
}
21522150
}
21532151
case (none[@ast::expr]) {

src/test/run-pass/expr-if-fail-all.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// xfail-stage0
2+
3+
// When all branches of an if expression result in fail, the entire if
4+
// expression results in fail.
5+
6+
fn main() {
7+
auto x = if (true) {
8+
10
9+
} else {
10+
if (true) {
11+
fail
12+
} else {
13+
fail
14+
}
15+
};
16+
}

0 commit comments

Comments
 (0)