Skip to content

Commit a0ec902

Browse files
dotdashalexcrichton
authored andcommitted
Avoid unnecessary temporary on assignments
We only need the temporary when the type needs to be dropped, for other types, we can use trans_into to directly place the value into the destination.
1 parent e4e3550 commit a0ec902

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/librustc/middle/trans/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,6 @@ fn trans_rvalue_stmt_unadjusted<'a>(bcx: &'a Block<'a>,
610610
controlflow::trans_loop(bcx, expr.id, &**body)
611611
}
612612
ast::ExprAssign(ref dst, ref src) => {
613-
let src_datum = unpack_datum!(bcx, trans(bcx, &**src));
614613
let dst_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, &**dst, "assign"));
615614

616615
if ty::type_needs_drop(bcx.tcx(), dst_datum.ty) {
@@ -630,12 +629,13 @@ fn trans_rvalue_stmt_unadjusted<'a>(bcx: &'a Block<'a>,
630629
//
631630
// We could avoid this intermediary with some analysis
632631
// to determine whether `dst` may possibly own `src`.
632+
let src_datum = unpack_datum!(bcx, trans(bcx, &**src));
633633
let src_datum = unpack_datum!(
634634
bcx, src_datum.to_rvalue_datum(bcx, "ExprAssign"));
635635
bcx = glue::drop_ty(bcx, dst_datum.val, dst_datum.ty);
636636
src_datum.store_to(bcx, dst_datum.val)
637637
} else {
638-
src_datum.store_to(bcx, dst_datum.val)
638+
trans_into(bcx, &**src, SaveIn(dst_datum.to_llref()))
639639
}
640640
}
641641
ast::ExprAssignOp(op, ref dst, ref src) => {

0 commit comments

Comments
 (0)