rust/src/test/run-pass/task-spawn-move-and-copy.rs
Marijn Haverbeke 0da1aca498 Recognize last uses for copied closed-over variables
And clean up and fix some bad things in last_use.rs.

Closes #1894
2012-02-29 18:06:26 +01:00

27 lines
657 B
Rust

fn main() {
let p = comm::port::<uint>();
let ch = comm::chan(p);
let x = ~1;
let x_in_parent = ptr::addr_of(*x) as uint;
let y = ~2;
let y_in_parent = ptr::addr_of(*y) as uint;
task::spawn(fn~[copy ch, y; move x]() {
let x_in_child = ptr::addr_of(*x) as uint;
comm::send(ch, x_in_child);
let y_in_child = ptr::addr_of(*y) as uint;
comm::send(ch, y_in_child);
});
// Ensure last-use analysis doesn't move y to child.
let _q = y;
let x_in_child = comm::recv(p);
assert x_in_parent == x_in_child;
let y_in_child = comm::recv(p);
assert y_in_parent != y_in_child;
}