Issue #7444 - Borrowck permits moved values to be captured
This commit is contained in:
parent
a93244dbf6
commit
81c576cd5b
@ -639,15 +639,14 @@ fn check_captured_variables(this: @mut CheckLoanCtxt,
|
||||
span: span) {
|
||||
let cap_vars = this.bccx.capture_map.get(&closure_id);
|
||||
for cap_vars.iter().advance |cap_var| {
|
||||
let var_id = ast_util::def_id_of_def(cap_var.def).node;
|
||||
let var_path = @LpVar(var_id);
|
||||
this.check_if_path_is_moved(closure_id, span,
|
||||
MovedInCapture, var_path);
|
||||
match cap_var.mode {
|
||||
moves::CapRef | moves::CapCopy => {
|
||||
let var_id = ast_util::def_id_of_def(cap_var.def).node;
|
||||
let lp = @LpVar(var_id);
|
||||
this.check_if_path_is_moved(closure_id, span,
|
||||
MovedInCapture, lp);
|
||||
}
|
||||
moves::CapRef | moves::CapCopy => {}
|
||||
moves::CapMove => {
|
||||
check_by_move_capture(this, closure_id, cap_var);
|
||||
check_by_move_capture(this, closure_id, cap_var, var_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -655,9 +654,8 @@ fn check_captured_variables(this: @mut CheckLoanCtxt,
|
||||
|
||||
fn check_by_move_capture(this: @mut CheckLoanCtxt,
|
||||
closure_id: ast::node_id,
|
||||
cap_var: &moves::CaptureVar) {
|
||||
let var_id = ast_util::def_id_of_def(cap_var.def).node;
|
||||
let move_path = @LpVar(var_id);
|
||||
cap_var: &moves::CaptureVar,
|
||||
move_path: @LoanPath) {
|
||||
let move_err = this.analyze_move_out_from(closure_id, move_path);
|
||||
match move_err {
|
||||
MoveOk => {}
|
||||
|
@ -385,7 +385,6 @@ pub fn vars_created_since_snapshot(&mut self, snapshot: uint)
|
||||
|
||||
pub fn tainted(&mut self, snapshot: uint, r0: Region) -> ~[Region] {
|
||||
/*!
|
||||
*
|
||||
* Computes all regions that have been related to `r0` in any
|
||||
* way since the snapshot `snapshot` was taken---`r0` itself
|
||||
* will be the first entry. This is used when checking whether
|
||||
|
@ -0,0 +1,10 @@
|
||||
fn call_f(f: ~fn:Send() -> int) -> int {
|
||||
f()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let t = ~3;
|
||||
|
||||
call_f(|| { *t + 1 });
|
||||
call_f(|| { *t + 1 }); //~ ERROR capture of moved value
|
||||
}
|
Loading…
Reference in New Issue
Block a user