Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions src/librustc/middle/trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,22 +828,33 @@ pub fn trans_arg_expr(bcx: block,
ty::ByCopy => {
debug!("by copy arg with type %s, storing to scratch",
bcx.ty_to_str(arg_datum.ty));
let scratch = scratch_datum(bcx, arg_datum.ty, false);

arg_datum.store_to_datum(bcx,
arg_expr.id,
INIT,
scratch);

// Technically, ownership of val passes to the callee.
// However, we must cleanup should we fail before the
// callee is actually invoked.
scratch.add_clean(bcx);
temp_cleanups.push(scratch.val);

match arg_datum.appropriate_mode() {
ByValue => val = Load(bcx, scratch.val),
ByRef(_) => val = scratch.val,
if ty::type_needs_drop(bcx.tcx(), arg_datum.ty) ||
arg_datum.appropriate_mode().is_by_ref() {
debug!("by copy arg with type %s, storing to scratch",
bcx.ty_to_str(arg_datum.ty));
let scratch = scratch_datum(bcx, arg_datum.ty, false);

arg_datum.store_to_datum(bcx,
arg_expr.id,
INIT,
scratch);

// Technically, ownership of val passes to the callee.
// However, we must cleanup should we fail before the
// callee is actually invoked.
scratch.add_clean(bcx);
temp_cleanups.push(scratch.val);

match scratch.appropriate_mode() {
ByValue => val = Load(bcx, scratch.val),
ByRef(_) => val = scratch.val,
}
} else {
debug!("by copy arg with type %s");
match arg_datum.mode {
ByRef(_) => val = Load(bcx, arg_datum.val),
ByValue => val = arg_datum.val,
}
}
}
}
Expand Down