Skip to content

Commit 7d69712

Browse files
committed
Disallow implicit arg copying when the function returns a ref
Issue #918
1 parent 93d2a4f commit 7d69712

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/comp/middle/alias.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ fn cant_copy(cx: ctx, b: binding) -> bool {
176176

177177
fn check_call(cx: ctx, f: @ast::expr, args: [@ast::expr]) -> [binding] {
178178
let fty = ty::type_autoderef(cx.tcx, ty::expr_ty(cx.tcx, f));
179+
let ret_ref = ty::ty_fn_ret_style(cx.tcx, fty) == ast::return_ref;
179180
let arg_ts = ty::ty_fn_args(cx.tcx, fty);
180181
let mut_roots: [{arg: uint, node: node_id}] = [];
181182
let bindings = [];
@@ -197,7 +198,7 @@ fn check_call(cx: ctx, f: @ast::expr, args: [@ast::expr]) -> [binding] {
197198
inner_mut(root.ds));
198199
new_bnd.copied = alt arg_t.mode {
199200
ast::by_move. { copied }
200-
ast::by_ref. { not_copied }
201+
ast::by_ref. { ret_ref ? not_allowed : not_copied }
201202
ast::by_mut_ref. { not_allowed }
202203
};
203204
bindings += [new_bnd];

0 commit comments

Comments
 (0)