Make heap closures always require a capture clause to capture mutable variables. Closes #2446.
This commit is contained in:
parent
736ff34e8a
commit
b744f52620
@ -96,10 +96,8 @@ fn with_appropriate_checker(cx: ctx, id: node_id, b: fn(check_fn)) {
|
||||
if !is_move { check_copy(cx, var_t, sp, is_implicit); }
|
||||
|
||||
// check that only immutable variables are implicitly copied in
|
||||
if !is_move {
|
||||
for fv.each { |fv|
|
||||
check_imm_free_var(cx, fv.def, fv.span);
|
||||
}
|
||||
for fv.each { |fv|
|
||||
check_imm_free_var(cx, fv.def, fv.span);
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,10 +108,8 @@ fn with_appropriate_checker(cx: ctx, id: node_id, b: fn(check_fn)) {
|
||||
if !is_move { check_copy(cx, var_t, sp, is_implicit); }
|
||||
|
||||
// check that only immutable variables are implicitly copied in
|
||||
if !is_move {
|
||||
for fv.each { |fv|
|
||||
check_imm_free_var(cx, fv.def, fv.span);
|
||||
}
|
||||
for fv.each { |fv|
|
||||
check_imm_free_var(cx, fv.def, fv.span);
|
||||
}
|
||||
}
|
||||
|
||||
@ -391,8 +387,8 @@ fn check_imm_free_var(cx: ctx, def: def, sp: span) {
|
||||
}
|
||||
def_arg(_, mode) {
|
||||
alt ty::resolved_mode(cx.tcx, mode) {
|
||||
by_ref | by_val { /* ok */ }
|
||||
by_mutbl_ref | by_move | by_copy {
|
||||
by_ref | by_val | by_move | by_copy { /* ok */ }
|
||||
by_mutbl_ref {
|
||||
cx.tcx.sess.span_err(sp, msg);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
fn use(_i: int) {}
|
||||
|
||||
fn foo() {
|
||||
// Here, i is *moved* into the closure: OK
|
||||
// Here, i is *moved* into the closure: Not actually OK
|
||||
let mut i = 0;
|
||||
task::spawn {||
|
||||
use(i);
|
||||
use(i); //! ERROR mutable variables cannot be implicitly captured
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,4 +32,4 @@ fn car() {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user