@@ -13,6 +13,7 @@ use rustc_middle::ty::cast::{CastTy, IntTy};
1313use rustc_middle:: ty:: layout:: { HasTyCtxt , LayoutOf } ;
1414use rustc_middle:: ty:: { self , adjustment:: PointerCast , Instance , Ty , TyCtxt } ;
1515use rustc_span:: source_map:: { Span , DUMMY_SP } ;
16+ use rustc_target:: abi:: VariantIdx ;
1617
1718impl < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > FunctionCx < ' a , ' tcx , Bx > {
1819 #[ instrument( level = "trace" , skip( self , bx) ) ]
@@ -106,31 +107,31 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
106107 }
107108
108109 mir:: Rvalue :: Aggregate ( ref kind, ref operands) => {
109- let ( dest, active_field_index) = match * * kind {
110- mir:: AggregateKind :: Adt ( adt_did, variant_index, _, _, active_field_index) => {
111- dest. codegen_set_discr ( bx, variant_index) ;
112- if bx. tcx ( ) . adt_def ( adt_did) . is_enum ( ) {
113- ( dest. project_downcast ( bx, variant_index) , active_field_index)
114- } else {
115- ( dest, active_field_index)
116- }
110+ let ( variant_index, variant_dest, active_field_index) = match * * kind {
111+ mir:: AggregateKind :: Adt ( _, variant_index, _, _, active_field_index) => {
112+ let variant_dest = dest. project_downcast ( bx, variant_index) ;
113+ ( variant_index, variant_dest, active_field_index)
117114 }
118- _ => ( dest, None ) ,
115+ _ => ( VariantIdx :: from_u32 ( 0 ) , dest, None ) ,
119116 } ;
117+ if active_field_index. is_some ( ) {
118+ assert_eq ! ( operands. len( ) , 1 ) ;
119+ }
120120 for ( i, operand) in operands. iter ( ) . enumerate ( ) {
121121 let op = self . codegen_operand ( bx, operand) ;
122122 // Do not generate stores and GEPis for zero-sized fields.
123123 if !op. layout . is_zst ( ) {
124124 let field_index = active_field_index. unwrap_or ( i) ;
125125 let field = if let mir:: AggregateKind :: Array ( _) = * * kind {
126126 let llindex = bx. cx ( ) . const_usize ( field_index as u64 ) ;
127- dest . project_index ( bx, llindex)
127+ variant_dest . project_index ( bx, llindex)
128128 } else {
129- dest . project_field ( bx, field_index)
129+ variant_dest . project_field ( bx, field_index)
130130 } ;
131131 op. val . store ( bx, field) ;
132132 }
133133 }
134+ dest. codegen_set_discr ( bx, variant_index) ;
134135 }
135136
136137 _ => {
0 commit comments