Skip to content

Commit 8ad7c28

Browse files
committed
Add comments to clarify function argument ownership
1 parent 0473a4f commit 8ad7c28

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/librustc/mir/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,9 @@ pub enum TerminatorKind<'tcx> {
650650
Call {
651651
/// The function that’s being called
652652
func: Operand<'tcx>,
653-
/// Arguments the function is called with
653+
/// Arguments the function is called with. These are owned by the callee, which is free to
654+
/// modify them. This is important as "by-value" arguments might be passed by-reference at
655+
/// the ABI level.
654656
args: Vec<Operand<'tcx>>,
655657
/// Destination for the return value. If some, the call is converging.
656658
destination: Option<(Lvalue<'tcx>, BasicBlock)>,

src/librustc_mir/build/expr/into.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
249249
args.into_iter()
250250
.map(|arg| {
251251
let scope = this.local_scope();
252+
// Function arguments are owned by the callee, so we need as_temp()
253+
// instead of as_operand() to enforce copies
252254
let operand = unpack!(block = this.as_temp(block, scope, arg));
253255
Operand::Consume(Lvalue::Local(operand))
254256
})

0 commit comments

Comments
 (0)