@@ -310,7 +310,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
310
310
operands : & IndexSlice < FieldIdx , mir:: Operand < ' tcx > > ,
311
311
dest : & PlaceTy < ' tcx , M :: Provenance > ,
312
312
) -> InterpResult < ' tcx > {
313
- self . write_uninit ( dest) ?; // make sure all the padding ends up as uninit
314
313
let ( variant_index, variant_dest, active_field_index) = match * kind {
315
314
mir:: AggregateKind :: Adt ( _, variant_index, _, _, active_field_index) => {
316
315
let variant_dest = self . project_downcast ( dest, variant_index) ?;
@@ -346,9 +345,20 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
346
345
let field_index = active_field_index. unwrap_or ( field_index) ;
347
346
let field_dest = self . project_field ( & variant_dest, field_index) ?;
348
347
let op = self . eval_operand ( operand, Some ( field_dest. layout ) ) ?;
349
- self . copy_op ( & op, & field_dest) ?;
348
+ // We validate manually below so we don't have to do it here.
349
+ self . copy_op_no_validate ( & op, & field_dest, /*allow_transmute*/ false ) ?;
350
350
}
351
- self . write_discriminant ( variant_index, dest)
351
+ self . write_discriminant ( variant_index, dest) ?;
352
+ // Validate that the entire thing is valid, and reset padding that might be in between the
353
+ // fields.
354
+ if M :: enforce_validity ( self , dest. layout ( ) ) {
355
+ self . validate_operand (
356
+ dest,
357
+ M :: enforce_validity_recursively ( self , dest. layout ( ) ) ,
358
+ /*reset_provenance_and_padding*/ true ,
359
+ ) ?;
360
+ }
361
+ interp_ok ( ( ) )
352
362
}
353
363
354
364
/// Repeats `operand` into the destination. `dest` must have array type, and that type
0 commit comments