auto merge of : nikomatsakis/rust/issue-7444-capture-moved-value, r=bblum

This code looks like it was just wrong. r? @bblum
This commit is contained in:
bors 2013-07-18 01:37:44 -07:00
commit cee5c4ad11
5 changed files with 26 additions and 12 deletions
src

@ -639,15 +639,14 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
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_loans_in_fn<'a>(fk: &visit::fn_kind,
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 @@ impl RegionVarBindings {
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

@ -4,8 +4,10 @@ pub fn main() {
let _f: @fn() -> int = || *foo + 5;
//~^ ERROR cannot move `foo`
// FIXME(#2202) - Due to the way that borrowck treats closures,
// you get two error reports here.
let bar = ~3;
let _g = || { //~ ERROR capture of moved value
let _h: @fn() -> int = || *bar;
let _h: @fn() -> int = || *bar; //~ ERROR capture of moved value
};
}

@ -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
}

@ -0,0 +1,5 @@
pub fn main() {
let bar = ~3;
let h: @fn() -> int = || *bar;
assert_eq!(h(), 3);
}