]> git.lizzy.rs Git - rust.git/commitdiff
Fix translation for all other discriminated ADTs
authorSimonas Kazlauskas <git@kazlauskas.me>
Thu, 14 Jan 2016 00:55:46 +0000 (02:55 +0200)
committerSimonas Kazlauskas <git@kazlauskas.me>
Fri, 15 Jan 2016 18:27:53 +0000 (20:27 +0200)
Again.

src/librustc_trans/trans/mir/rvalue.rs

index f0842554277cc7e50fcfcaa1bf824665bb25d325..7b9eac4317d24b06e88ab426801db348a18f436e 100644 (file)
@@ -98,13 +98,19 @@ pub fn trans_rvalue(&mut self,
 
             mir::Rvalue::Aggregate(ref kind, ref operands) => {
                 match *kind {
-                    // Unit struct or variant; both are translated very differently compared to any
-                    // other aggregate
-                    mir::AggregateKind::Adt(adt_def, index, _)
-                    if adt_def.variants[index].kind() == ty::VariantKind::Unit => {
+                    mir::AggregateKind::Adt(adt_def, index, _) => {
                         let repr = adt::represent_type(bcx.ccx(), dest.ty.to_ty(bcx.tcx()));
                         let disr = adt_def.variants[index].disr_val;
                         adt::trans_set_discr(bcx, &*repr, dest.llval, disr);
+                        for (i, operand) in operands.iter().enumerate() {
+                            let op = self.trans_operand(bcx, operand);
+                            // Do not generate stores and GEPis for zero-sized fields.
+                            if !common::type_is_zero_size(bcx.ccx(), op.ty) {
+                                let val = adt::MaybeSizedValue::sized(dest.llval);
+                                let lldest_i = adt::trans_field_ptr(bcx, &*repr, val, disr, i);
+                                self.store_operand(bcx, lldest_i, op);
+                            }
+                        }
                     },
                     _ => {
                         for (i, operand) in operands.iter().enumerate() {