Skip to content

Commit 8594f87

Browse files
committed
Emit SetDiscriminant before cloning
1 parent 84558e8 commit 8594f87

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/librustc_mir/shim.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,19 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
712712
let src_variant = receiver.clone().downcast(adt, idx);
713713
let dest_variant = dest.clone().downcast(adt, idx);
714714

715-
// next block created will be the target
716-
targets.push(self.block_index_offset(0));
717-
// the borrow
715+
716+
// the next to next block created will be the one
717+
// from tuple_like_shim and will handle the cloning
718+
let clone_block = self.block_index_offset(1);
719+
let set_discr = self.make_statement(StatementKind::SetDiscriminant {
720+
place: dest.clone(),
721+
variant_index: idx
722+
});
723+
724+
targets.push(self.block(vec![set_discr], TerminatorKind::Goto {
725+
target: clone_block
726+
}, false));
727+
718728
let tcx = self.tcx;
719729
let iter = variant.fields.iter().map(|field| field.ty(tcx, substs));
720730
self.tuple_like_shim(src_variant, dest_variant, iter);

0 commit comments

Comments
 (0)