Skip to content

Commit

Permalink
Add comments to clarify function argument ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
dotdash committed Oct 26, 2017
1 parent 0473a4f commit 8ad7c28
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Operand<'tcx>>,
/// Destination for the return value. If some, the call is converging.
destination: Option<(Lvalue<'tcx>, BasicBlock)>,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_mir/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down

0 comments on commit 8ad7c28

Please sign in to comment.