From 8ad7c284d793250edffe0e85f6cc898585496283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Wed, 25 Oct 2017 13:04:59 +0200 Subject: [PATCH] Add comments to clarify function argument ownership --- src/librustc/mir/mod.rs | 4 +++- src/librustc_mir/build/expr/into.rs | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 0159a198bc6..f5a3c1989cf 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -650,7 +650,9 @@ pub enum TerminatorKind<'tcx> { Call { /// The function that’s 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>, /// Destination for the return value. If some, the call is converging. destination: Option<(Lvalue<'tcx>, BasicBlock)>, diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index 3d7abefd284..280e1c81966 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -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)) })