Closed
Description
This fails:
fn main() {
let x = ~1;
let x_in_parent = ptr::addr_of(*x) as uint;
let f = fn@() -> uint {
ptr::addr_of(*x) as uint
};
let x_in_child = f();
assert x_in_parent == x_in_child;
}
Rewriting it with a capture clause works:
fn main() {
let x = ~1;
let x_in_parent = ptr::addr_of(*x) as uint;
let f = fn@[move x]() -> uint {
ptr::addr_of(*x) as uint
};
let x_in_child = f();
assert x_in_parent == x_in_child;
}
This is a bit surprising and makes spawn not do the expected thing when written with the convenient block closure syntax. For this reason core::task uses fn~
closures with explicit capture clauses.
Metadata
Metadata
Assignees
Labels
No labels