提交 cee5c4ad 编写于 作者: B bors

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

This code looks like it was just wrong. r? @bblum
......@@ -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
......
......@@ -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
};
}
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
}
pub fn main() {
let bar = ~3;
let h: @fn() -> int = || *bar;
assert_eq!(h(), 3);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册