Skip to content

Commit 1e52662

Browse files
committed
Take move captures in account in mutability checker
Closes #1461
1 parent 8015e6d commit 1e52662

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/comp/middle/mutbl.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ fn visit_expr(cx: @ctx, ex: @expr, &&e: (), v: visit::vt<()>) {
172172
expr_assign(dest, src) | expr_assign_op(_, dest, src) {
173173
check_lval(cx, dest, msg_assign);
174174
}
175+
expr_fn(_, _, _, cap) {
176+
for moved in cap.moves {
177+
let def = cx.tcx.def_map.get(moved.id);
178+
alt is_immutable_def(cx, def) {
179+
some(name) { mk_err(cx, moved.span, msg_move_out, moved.name); }
180+
_ { }
181+
}
182+
cx.mutbl_map.insert(ast_util::def_id_of_def(def).node, ());
183+
}
184+
}
175185
_ { }
176186
}
177187
visit::visit_expr(ex, e, v);

src/comp/middle/trans/closure.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,9 @@ fn build_closure(bcx0: block,
376376
env_vals += [env_move(lv.val, ty, lv.kind)];
377377
}
378378
capture::cap_drop {
379+
assert lv.kind == owned;
379380
bcx = drop_ty(bcx, lv.val, ty);
381+
bcx = zero_alloca(bcx, lv.val, ty);
380382
}
381383
}
382384
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
let x = ~1;
3+
let lam_move = fn@[move x]() { };
4+
lam_move();
5+
}

0 commit comments

Comments
 (0)