@@ -754,10 +754,9 @@ fn trans_rvalue_dps_unadjusted<'a>(bcx: &'a Block<'a>,
754
754
dest)
755
755
}
756
756
ast:: ExprTup ( ref args) => {
757
- let repr = adt:: represent_type ( bcx. ccx ( ) , expr_ty ( bcx, expr) ) ;
758
757
let numbered_fields: Vec < ( uint , Gc < ast:: Expr > ) > =
759
758
args. iter ( ) . enumerate ( ) . map ( |( i, arg) | ( i, * arg) ) . collect ( ) ;
760
- trans_adt ( bcx, & * repr , 0 , numbered_fields. as_slice ( ) , None , dest)
759
+ trans_adt ( bcx, expr_ty ( bcx , expr ) , 0 , numbered_fields. as_slice ( ) , None , dest)
761
760
}
762
761
ast:: ExprLit ( lit) => {
763
762
match lit. node {
@@ -1089,8 +1088,7 @@ fn trans_struct<'a>(bcx: &'a Block<'a>,
1089
1088
}
1090
1089
} ;
1091
1090
1092
- let repr = adt:: represent_type ( bcx. ccx ( ) , ty) ;
1093
- trans_adt ( bcx, & * repr, discr, numbered_fields. as_slice ( ) , optbase, dest)
1091
+ trans_adt ( bcx, ty, discr, numbered_fields. as_slice ( ) , optbase, dest)
1094
1092
} )
1095
1093
}
1096
1094
@@ -1119,25 +1117,20 @@ pub struct StructBaseInfo {
1119
1117
* which remaining fields are copied; see comments on `StructBaseInfo`.
1120
1118
*/
1121
1119
pub fn trans_adt < ' a > ( mut bcx : & ' a Block < ' a > ,
1122
- repr : & adt :: Repr ,
1120
+ ty : ty :: t ,
1123
1121
discr : ty:: Disr ,
1124
1122
fields : & [ ( uint , Gc < ast:: Expr > ) ] ,
1125
1123
optbase : Option < StructBaseInfo > ,
1126
1124
dest : Dest ) -> & ' a Block < ' a > {
1127
1125
let _icx = push_ctxt ( "trans_adt" ) ;
1128
1126
let fcx = bcx. fcx ;
1127
+ let repr = adt:: represent_type ( bcx. ccx ( ) , ty) ;
1128
+
1129
+ // If we don't care about the result, just make a
1130
+ // temporary stack slot
1129
1131
let addr = match dest {
1130
- Ignore => {
1131
- for & ( _i, ref e) in fields. iter ( ) {
1132
- bcx = trans_into ( bcx, & * * e, Ignore ) ;
1133
- }
1134
- for sbi in optbase. iter ( ) {
1135
- // FIXME #7261: this moves entire base, not just certain fields
1136
- bcx = trans_into ( bcx, & * sbi. expr , Ignore ) ;
1137
- }
1138
- return bcx;
1139
- }
1140
- SaveIn ( pos) => pos
1132
+ SaveIn ( pos) => pos,
1133
+ Ignore => alloc_ty ( bcx, ty, "temp" ) ,
1141
1134
} ;
1142
1135
1143
1136
// This scope holds intermediates that must be cleaned should
@@ -1153,8 +1146,8 @@ pub fn trans_adt<'a>(mut bcx: &'a Block<'a>,
1153
1146
let base_datum = unpack_datum ! ( bcx, trans_to_lvalue( bcx, & * base. expr, "base" ) ) ;
1154
1147
for & ( i, t) in base. fields . iter ( ) {
1155
1148
let datum = base_datum. get_element (
1156
- t, |srcval| adt:: trans_field_ptr ( bcx, repr, srcval, discr, i) ) ;
1157
- let dest = adt:: trans_field_ptr ( bcx, repr, addr, discr, i) ;
1149
+ t, |srcval| adt:: trans_field_ptr ( bcx, & * repr, srcval, discr, i) ) ;
1150
+ let dest = adt:: trans_field_ptr ( bcx, & * repr, addr, discr, i) ;
1158
1151
bcx = datum. store_to ( bcx, dest) ;
1159
1152
}
1160
1153
} ,
@@ -1167,19 +1160,27 @@ pub fn trans_adt<'a>(mut bcx: &'a Block<'a>,
1167
1160
1168
1161
// Now, we just overwrite the fields we've explicity specified
1169
1162
for & ( i, ref e) in fields. iter ( ) {
1170
- let dest = adt:: trans_field_ptr ( bcx, repr, addr, discr, i) ;
1163
+ let dest = adt:: trans_field_ptr ( bcx, & * repr, addr, discr, i) ;
1171
1164
let e_ty = expr_ty_adjusted ( bcx, & * * e) ;
1172
1165
bcx = trans_into ( bcx, & * * e, SaveIn ( dest) ) ;
1173
1166
let scope = cleanup:: CustomScope ( custom_cleanup_scope) ;
1174
1167
fcx. schedule_lifetime_end ( scope, dest) ;
1175
1168
fcx. schedule_drop_mem ( scope, dest, e_ty) ;
1176
1169
}
1177
1170
1178
- adt:: trans_set_discr ( bcx, repr, addr, discr) ;
1171
+ adt:: trans_set_discr ( bcx, & * repr, addr, discr) ;
1179
1172
1180
1173
fcx. pop_custom_cleanup_scope ( custom_cleanup_scope) ;
1181
1174
1182
- return bcx;
1175
+ // If we don't care about the result drop the temporary we made
1176
+ match dest {
1177
+ SaveIn ( _) => bcx,
1178
+ Ignore => {
1179
+ bcx = glue:: drop_ty ( bcx, addr, ty) ;
1180
+ base:: call_lifetime_end ( bcx, addr) ;
1181
+ bcx
1182
+ }
1183
+ }
1183
1184
}
1184
1185
1185
1186
0 commit comments