Add comments to clarify function argument ownership

This commit is contained in:
Björn Steinbrink 2017-10-25 13:04:59 +02:00
parent 0473a4f1d8
commit 8ad7c284d7
2 changed files with 5 additions and 1 deletions

View File

@ -650,7 +650,9 @@ pub enum TerminatorKind<'tcx> {
Call {
/// The function thats being called
func: Operand<'tcx>,
/// Arguments the function is called with
/// Arguments the function is called with. These are owned by the callee, which is free to
/// modify them. This is important as "by-value" arguments might be passed by-reference at
/// the ABI level.
args: Vec<Operand<'tcx>>,
/// Destination for the return value. If some, the call is converging.
destination: Option<(Lvalue<'tcx>, BasicBlock)>,

View File

@ -249,6 +249,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
args.into_iter()
.map(|arg| {
let scope = this.local_scope();
// Function arguments are owned by the callee, so we need as_temp()
// instead of as_operand() to enforce copies
let operand = unpack!(block = this.as_temp(block, scope, arg));
Operand::Consume(Lvalue::Local(operand))
})