diff options
| author | bors <bors@rust-lang.org> | 2014-08-15 20:31:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-08-15 20:31:16 +0000 |
| commit | 2da501883884ab6add110ee1b8dea05ff8d8f013 (patch) | |
| tree | 3e874a1406111f15782b2c65177f7aacdeeb8e0a | |
| parent | 02f9fd87ec56b1e84d45c96abe388f555e28faed (diff) | |
| parent | 6c5d97a5da043c785b2fb38c0fd13c85ab265122 (diff) | |
| download | rust-2da501883884ab6add110ee1b8dea05ff8d8f013.tar.gz rust-2da501883884ab6add110ee1b8dea05ff8d8f013.zip | |
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.
| -rw-r--r-- | src/librustc/middle/trans/controlflow.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index a481f92db33..193303f4d1c 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -330,13 +330,12 @@ pub fn trans_for<'a>( // Check the discriminant; if the `None` case, exit the loop. let option_representation = adt::represent_type(loopback_bcx_out.ccx(), method_result_type); - let i8_type = Type::i8(loopback_bcx_out.ccx()); let lldiscriminant = adt::trans_get_discr(loopback_bcx_out, &*option_representation, option_datum.val, - Some(i8_type)); - let llzero = C_u8(loopback_bcx_out.ccx(), 0); - let llcondition = ICmp(loopback_bcx_out, IntNE, lldiscriminant, llzero); + None); + let i1_type = Type::i1(loopback_bcx_out.ccx()); + let llcondition = Trunc(loopback_bcx_out, lldiscriminant, i1_type); CondBr(loopback_bcx_out, llcondition, body_bcx_in.llbb, cleanup_llbb); // Now we're in the body. Unpack the `Option` value into the programmer- |
