blob: 3b3836dd32e0b4e8ac55704f73a6a5642e31d96b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Resources can't be copied, but storing into data structures counts
// as a move unless the stored thing is used afterwards.
resource r(i: @mutable int) {
*i = *i + 1;
}
fn test_box() {
let i = @mutable 0;
{
let a <- @r(i);
}
assert *i == 1;
}
fn test_rec() {
let i = @mutable 0;
{
let a <- {x: r(i)};
}
assert *i == 1;
}
fn test_tag() {
enum t {
t0(r),
}
let i = @mutable 0;
{
let a <- t0(r(i));
}
assert *i == 1;
}
fn test_tup() {
let i = @mutable 0;
{
let a <- (r(i), 0);
}
assert *i == 1;
}
fn test_unique() {
let i = @mutable 0;
{
let a <- ~r(i);
}
assert *i == 1;
}
fn test_box_rec() {
let i = @mutable 0;
{
let a <- @{
x: r(i)
};
}
assert *i == 1;
}
fn main() {
test_box();
test_rec();
// FIXME: enum constructors don't optimize their arguments into moves
// test_tag();
test_tup();
test_unique();
test_box_rec();
}
|