]> git.lizzy.rs Git - rust.git/commitdiff
C-like enums are not always immediate
authorJed Davis <jld@panix.com>
Thu, 3 Oct 2013 20:59:34 +0000 (13:59 -0700)
committerJed Davis <jld@panix.com>
Tue, 29 Oct 2013 16:09:20 +0000 (09:09 -0700)
src/librustc/middle/trans/expr.rs

index e1de66152069d28b7dc2be6963b94cacf35590f8..9a019f98a493c5857f9ad3029cbb64483dd2e1aa 100644 (file)
@@ -1726,9 +1726,14 @@ fn trans_imm_cast(bcx: @mut Block, expr: &ast::Expr,
             (cast_enum, cast_float) => {
                 let bcx = bcx;
                 let repr = adt::represent_type(ccx, t_in);
-                let slot = Alloca(bcx, ll_t_in, "");
-                Store(bcx, llexpr, slot);
-                let lldiscrim_a = adt::trans_get_discr(bcx, repr, slot, Some(Type::i64()));
+                let llexpr_ptr;
+                if type_is_immediate(ccx, t_in) {
+                    llexpr_ptr = Alloca(bcx, ll_t_in, "");
+                    Store(bcx, llexpr, llexpr_ptr);
+                } else {
+                    llexpr_ptr = llexpr;
+                }
+                let lldiscrim_a = adt::trans_get_discr(bcx, repr, llexpr_ptr, Some(Type::i64()));
                 match k_out {
                     cast_integral => int_cast(bcx, ll_t_out,
                                               val_ty(lldiscrim_a),