@@ -790,17 +790,30 @@ fn codegen_stmt<'tcx>(
790790 let val = CValue :: const_val ( fx, fx. layout_of ( fx. tcx . types . usize ) , val. into ( ) ) ;
791791 lval. write_cvalue ( fx, val) ;
792792 }
793- Rvalue :: Aggregate ( ref kind, ref operands) => match kind. as_ref ( ) {
794- AggregateKind :: Array ( _ty) => {
795- for ( i, operand) in operands. iter ( ) . enumerate ( ) {
796- let operand = codegen_operand ( fx, operand) ;
797- let index = fx. bcx . ins ( ) . iconst ( fx. pointer_type , i as i64 ) ;
798- let to = lval. place_index ( fx, index) ;
799- to. write_cvalue ( fx, operand) ;
793+ Rvalue :: Aggregate ( ref kind, ref operands) => {
794+ let ( variant_index, variant_dest, active_field_index) = match * * kind {
795+ mir:: AggregateKind :: Adt ( _, variant_index, _, _, active_field_index) => {
796+ let variant_dest = lval. downcast_variant ( fx, variant_index) ;
797+ ( variant_index, variant_dest, active_field_index)
800798 }
799+ _ => ( VariantIdx :: from_u32 ( 0 ) , lval, None ) ,
800+ } ;
801+ if active_field_index. is_some ( ) {
802+ assert_eq ! ( operands. len( ) , 1 ) ;
801803 }
802- _ => unreachable ! ( "shouldn't exist at codegen {:?}" , to_place_and_rval. 1 ) ,
803- } ,
804+ for ( i, operand) in operands. iter ( ) . enumerate ( ) {
805+ let operand = codegen_operand ( fx, operand) ;
806+ let field_index = active_field_index. unwrap_or ( i) ;
807+ let to = if let mir:: AggregateKind :: Array ( _) = * * kind {
808+ let index = fx. bcx . ins ( ) . iconst ( fx. pointer_type , field_index as i64 ) ;
809+ variant_dest. place_index ( fx, index)
810+ } else {
811+ variant_dest. place_field ( fx, mir:: Field :: new ( field_index) )
812+ } ;
813+ to. write_cvalue ( fx, operand) ;
814+ }
815+ crate :: discriminant:: codegen_set_discriminant ( fx, lval, variant_index) ;
816+ }
804817 }
805818 }
806819 StatementKind :: StorageLive ( _)
0 commit comments