rust/src/test/run-pass/cap-clause-move.rs

30 lines
1009 B
Rust
Raw Normal View History

fn main() {
let x = ~1;
let y = ptr::addr_of(*x) as uint;
2012-05-04 14:33:04 -05:00
let lam_copy = fn@(copy x) -> uint { ptr::addr_of(*x) as uint };
let lam_move = fn@(move x) -> uint { ptr::addr_of(*x) as uint };
assert lam_copy() != y;
assert lam_move() == y;
let x = ~2;
let y = ptr::addr_of(*x) as uint;
2012-06-30 18:19:07 -05:00
let lam_copy: fn@() -> uint = |copy x| ptr::addr_of(*x) as uint;
let lam_move: fn@() -> uint = |move x| ptr::addr_of(*x) as uint;
2012-05-04 14:33:04 -05:00
assert lam_copy() != y;
assert lam_move() == y;
let x = ~3;
let y = ptr::addr_of(*x) as uint;
let snd_copy = fn~(copy x) -> uint { ptr::addr_of(*x) as uint };
let snd_move = fn~(move x) -> uint { ptr::addr_of(*x) as uint };
assert snd_copy() != y;
assert snd_move() == y;
2012-05-04 14:33:04 -05:00
let x = ~4;
let y = ptr::addr_of(*x) as uint;
2012-06-30 18:19:07 -05:00
let lam_copy: fn~() -> uint = |copy x| ptr::addr_of(*x) as uint;
let lam_move: fn~() -> uint = |move x| ptr::addr_of(*x) as uint;
2012-05-04 14:33:04 -05:00
assert lam_copy() != y;
assert lam_move() == y;
}