Skip to content

Commit 2da5018

Browse files
committed
auto merge of #16517 : dotdash/rust/for_trunc, r=pcwalton
The discriminant for Option values is either 0 or 1, so we can just truncate the value to an i1, which ends up as a no-op for Options containing pointers.
2 parents 02f9fd8 + 6c5d97a commit 2da5018

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/librustc/middle/trans/controlflow.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,12 @@ pub fn trans_for<'a>(
330330
// Check the discriminant; if the `None` case, exit the loop.
331331
let option_representation = adt::represent_type(loopback_bcx_out.ccx(),
332332
method_result_type);
333-
let i8_type = Type::i8(loopback_bcx_out.ccx());
334333
let lldiscriminant = adt::trans_get_discr(loopback_bcx_out,
335334
&*option_representation,
336335
option_datum.val,
337-
Some(i8_type));
338-
let llzero = C_u8(loopback_bcx_out.ccx(), 0);
339-
let llcondition = ICmp(loopback_bcx_out, IntNE, lldiscriminant, llzero);
336+
None);
337+
let i1_type = Type::i1(loopback_bcx_out.ccx());
338+
let llcondition = Trunc(loopback_bcx_out, lldiscriminant, i1_type);
340339
CondBr(loopback_bcx_out, llcondition, body_bcx_in.llbb, cleanup_llbb);
341340

342341
// Now we're in the body. Unpack the `Option` value into the programmer-

0 commit comments

Comments
 (0)