Skip to content

Commit 337d860

Browse files
committed
Make last-use finder treat referenced function arguments properly
Closes #1964
1 parent 1745ac9 commit 337d860

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/rustc/middle/last_use.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -163,24 +163,36 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
163163
}
164164
expr_call(f, args, _) {
165165
v.visit_expr(f, cx, v);
166-
let i = 0u, fns = [];
166+
let fns = [];
167167
let arg_ts = ty::ty_fn_args(ty::expr_ty(cx.tcx, f));
168-
for arg in args {
168+
vec::iter2(args, arg_ts) {|arg, arg_t|
169169
alt arg.node {
170170
expr_fn(_, _, _, _) | expr_fn_block(_, _)
171-
if is_blockish(ty::ty_fn_proto(arg_ts[i].ty)) {
171+
if is_blockish(ty::ty_fn_proto(arg_t.ty)) {
172172
fns += [arg];
173173
}
174174
_ {
175-
alt ty::arg_mode(cx.tcx, arg_ts[i]) {
175+
alt ty::arg_mode(cx.tcx, arg_t) {
176176
by_mutbl_ref { clear_if_path(cx, arg, v, false); }
177177
_ { v.visit_expr(arg, cx, v); }
178178
}
179179
}
180180
}
181-
i += 1u;
182181
}
183182
for f in fns { v.visit_expr(f, cx, v); }
183+
vec::iter2(args, arg_ts) {|arg, arg_t|
184+
alt arg.node {
185+
expr_path(_) {
186+
alt ty::arg_mode(cx.tcx, arg_t) {
187+
by_ref | by_val | by_mutbl_ref {
188+
clear_if_path(cx, arg, v, false);
189+
}
190+
_ {}
191+
}
192+
}
193+
_ {}
194+
}
195+
}
184196
}
185197
_ { visit::visit_expr(ex, cx, v); }
186198
}

0 commit comments

Comments
 (0)