Skip to content

Commit 7fd3c27

Browse files
committed
Write directly to the RETURN_PLACE in tuple_like_shim
1 parent e07aecd commit 7fd3c27

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

src/librustc_mir/shim.rs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
408408
rcvr_field: Place<'tcx>,
409409
next: BasicBlock,
410410
cleanup: BasicBlock,
411-
place: Place<'tcx>
411+
dest: Place<'tcx>
412412
) {
413413
let tcx = self.tcx;
414414

@@ -452,7 +452,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
452452
self.block(vec![statement], TerminatorKind::Call {
453453
func,
454454
args: vec![Operand::Move(ref_loc)],
455-
destination: Some((place, next)),
455+
destination: Some((dest, next)),
456456
cleanup: Some(cleanup),
457457
}, false);
458458
}
@@ -633,12 +633,13 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
633633

634634
let rcvr = Place::Local(Local::new(1+0)).deref();
635635

636-
let mut returns = Vec::new();
636+
let mut previous_place = None;
637+
let return_place = Place::Local(RETURN_PLACE);
637638
for (i, ity) in tys.iter().enumerate() {
638-
let rcvr_field = rcvr.clone().field(Field::new(i), *ity);
639+
let field = Field::new(i);
640+
let rcvr_field = rcvr.clone().field(field, *ity);
639641

640-
let place = self.make_place(Mutability::Not, ity);
641-
returns.push(place.clone());
642+
let place = return_place.clone().field(field, *ity);
642643

643644
// BB #(2i)
644645
// `returns[i] = Clone::clone(&rcvr.i);`
@@ -648,34 +649,26 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
648649
rcvr_field,
649650
BasicBlock::new(2 * i + 2),
650651
BasicBlock::new(2 * i + 1),
651-
place
652+
place.clone()
652653
);
653654

654655
// BB #(2i + 1) (cleanup)
655-
if i == 0 {
656-
// Nothing to drop, just resume.
657-
self.block(vec![], TerminatorKind::Resume, true);
658-
} else {
656+
if let Some(previous_place) = previous_place.take() {
659657
// Drop previous field and goto previous cleanup block.
660658
self.block(vec![], TerminatorKind::Drop {
661-
location: returns[i - 1].clone(),
659+
location: previous_place,
662660
target: BasicBlock::new(2 * i - 1),
663661
unwind: None,
664662
}, true);
663+
} else {
664+
// Nothing to drop, just resume.
665+
self.block(vec![], TerminatorKind::Resume, true);
665666
}
667+
668+
previous_place = Some(place);
666669
}
667670

668-
// `return kind(returns[0], returns[1], ..., returns[tys.len() - 1]);`
669-
let ret_statement = self.make_statement(
670-
StatementKind::Assign(
671-
Place::Local(RETURN_PLACE),
672-
Rvalue::Aggregate(
673-
box kind,
674-
returns.into_iter().map(Operand::Move).collect()
675-
)
676-
)
677-
);
678-
self.block(vec![ret_statement], TerminatorKind::Return, false);
671+
self.block(vec![], TerminatorKind::Return, false);
679672
}
680673
}
681674

0 commit comments

Comments
 (0)