Skip to content

Commit cee5c4a

Browse files
committedJul 18, 2013
auto merge of #7849 : nikomatsakis/rust/issue-7444-capture-moved-value, r=bblum
This code looks like it was just wrong. r? @bblum
2 parents 30ef79c + 782853c commit cee5c4a

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed
 

‎src/librustc/middle/borrowck/check_loans.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -639,25 +639,23 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
639639
span: span) {
640640
let cap_vars = this.bccx.capture_map.get(&closure_id);
641641
for cap_vars.iter().advance |cap_var| {
642+
let var_id = ast_util::def_id_of_def(cap_var.def).node;
643+
let var_path = @LpVar(var_id);
644+
this.check_if_path_is_moved(closure_id, span,
645+
MovedInCapture, var_path);
642646
match cap_var.mode {
643-
moves::CapRef | moves::CapCopy => {
644-
let var_id = ast_util::def_id_of_def(cap_var.def).node;
645-
let lp = @LpVar(var_id);
646-
this.check_if_path_is_moved(closure_id, span,
647-
MovedInCapture, lp);
648-
}
647+
moves::CapRef | moves::CapCopy => {}
649648
moves::CapMove => {
650-
check_by_move_capture(this, closure_id, cap_var);
649+
check_by_move_capture(this, closure_id, cap_var, var_path);
651650
}
652651
}
653652
}
654653
return;
655654

656655
fn check_by_move_capture(this: @mut CheckLoanCtxt,
657656
closure_id: ast::node_id,
658-
cap_var: &moves::CaptureVar) {
659-
let var_id = ast_util::def_id_of_def(cap_var.def).node;
660-
let move_path = @LpVar(var_id);
657+
cap_var: &moves::CaptureVar,
658+
move_path: @LoanPath) {
661659
let move_err = this.analyze_move_out_from(closure_id, move_path);
662660
match move_err {
663661
MoveOk => {}

‎src/librustc/middle/typeck/infer/region_inference/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ impl RegionVarBindings {
385385

386386
pub fn tainted(&mut self, snapshot: uint, r0: Region) -> ~[Region] {
387387
/*!
388-
*
389388
* Computes all regions that have been related to `r0` in any
390389
* way since the snapshot `snapshot` was taken---`r0` itself
391390
* will be the first entry. This is used when checking whether

‎src/test/compile-fail/borrowck-move-by-capture.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ pub fn main() {
44
let _f: @fn() -> int = || *foo + 5;
55
//~^ ERROR cannot move `foo`
66

7+
// FIXME(#2202) - Due to the way that borrowck treats closures,
8+
// you get two error reports here.
79
let bar = ~3;
810
let _g = || { //~ ERROR capture of moved value
9-
let _h: @fn() -> int = || *bar;
11+
let _h: @fn() -> int = || *bar; //~ ERROR capture of moved value
1012
};
1113
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn call_f(f: ~fn:Send() -> int) -> int {
2+
f()
3+
}
4+
5+
fn main() {
6+
let t = ~3;
7+
8+
call_f(|| { *t + 1 });
9+
call_f(|| { *t + 1 }); //~ ERROR capture of moved value
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn main() {
2+
let bar = ~3;
3+
let h: @fn() -> int = || *bar;
4+
assert_eq!(h(), 3);
5+
}

0 commit comments

Comments
 (0)