@@ -13,6 +13,7 @@ use rustc_middle::ty::cast::{CastTy, IntTy};
13
13
use rustc_middle:: ty:: layout:: { HasTyCtxt , LayoutOf } ;
14
14
use rustc_middle:: ty:: { self , adjustment:: PointerCast , Instance , Ty , TyCtxt } ;
15
15
use rustc_span:: source_map:: { Span , DUMMY_SP } ;
16
+ use rustc_target:: abi:: VariantIdx ;
16
17
17
18
impl < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > FunctionCx < ' a , ' tcx , Bx > {
18
19
#[ instrument( level = "trace" , skip( self , bx) ) ]
@@ -106,31 +107,31 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
106
107
}
107
108
108
109
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)
117
114
}
118
- _ => ( dest, None ) ,
115
+ _ => ( VariantIdx :: from_u32 ( 0 ) , dest, None ) ,
119
116
} ;
117
+ if active_field_index. is_some ( ) {
118
+ assert_eq ! ( operands. len( ) , 1 ) ;
119
+ }
120
120
for ( i, operand) in operands. iter ( ) . enumerate ( ) {
121
121
let op = self . codegen_operand ( bx, operand) ;
122
122
// Do not generate stores and GEPis for zero-sized fields.
123
123
if !op. layout . is_zst ( ) {
124
124
let field_index = active_field_index. unwrap_or ( i) ;
125
125
let field = if let mir:: AggregateKind :: Array ( _) = * * kind {
126
126
let llindex = bx. cx ( ) . const_usize ( field_index as u64 ) ;
127
- dest . project_index ( bx, llindex)
127
+ variant_dest . project_index ( bx, llindex)
128
128
} else {
129
- dest . project_field ( bx, field_index)
129
+ variant_dest . project_field ( bx, field_index)
130
130
} ;
131
131
op. val . store ( bx, field) ;
132
132
}
133
133
}
134
+ dest. codegen_set_discr ( bx, variant_index) ;
134
135
}
135
136
136
137
_ => {
0 commit comments