Skip to content

Commit cfae247

Browse files
committed
Rollup merge of rust-lang#21941 - dotdash:with_cond_false, r=Aatch
Currently \"k / 2\" generates one (k: uint) or two (k: int) \"br false, ...\" instructions and the corresponding basic blocks, producing quite some noise and making the code unnecessarily hard to read. Additionally we can skip translation if the code would end up unreachable anyway.
2 parents d1a1d33 + db8f2d5 commit cfae247

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/librustc_trans/trans/_match.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,11 +889,13 @@ fn compile_guard<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
889889
}
890890
}
891891

892+
for (_, &binding_info) in &data.bindings_map {
893+
bcx.fcx.lllocals.borrow_mut().remove(&binding_info.id);
894+
}
895+
892896
with_cond(bcx, Not(bcx, val, guard_expr.debug_loc()), |bcx| {
893-
// Guard does not match: remove all bindings from the lllocals table
894897
for (_, &binding_info) in &data.bindings_map {
895898
call_lifetime_end(bcx, binding_info.llmatch);
896-
bcx.fcx.lllocals.borrow_mut().remove(&binding_info.id);
897899
}
898900
match chk {
899901
// If the default arm is the only one left, move on to the next

src/librustc_trans/trans/base.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,12 @@ pub fn with_cond<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
10811081
F: FnOnce(Block<'blk, 'tcx>) -> Block<'blk, 'tcx>,
10821082
{
10831083
let _icx = push_ctxt("with_cond");
1084+
1085+
if bcx.unreachable.get() ||
1086+
(common::is_const(val) && common::const_to_uint(val) == 0) {
1087+
return bcx;
1088+
}
1089+
10841090
let fcx = bcx.fcx;
10851091
let next_cx = fcx.new_temp_block("next");
10861092
let cond_cx = fcx.new_temp_block("cond");

0 commit comments

Comments
 (0)