summary refs log tree commit diff
path: root/src/test/compile-fail/kindck-implicit-close-over-mut-var.rs
blob: f4a7816c1617c73f618fc9b765e902bc6d900596 (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
fn user(_i: int) {}

fn foo() {
    // Here, i is *moved* into the closure: Not actually OK
    let mut i = 0;
    do task::spawn {
        user(i); //~ ERROR mutable variables cannot be implicitly captured
    }
}

fn bar() {
    // Here, i would be implicitly *copied* but it
    // is mutable: bad
    let mut i = 0;
    while i < 10 {
        do task::spawn {
            user(i); //~ ERROR mutable variables cannot be implicitly captured
        }
        i += 1;
    }
}

fn car() {
    // Here, i is mutable, but *explicitly* copied:
    let mut i = 0;
    while i < 10 {
        do task::spawn |copy i| {
            user(i);
        }
        i += 1;
    }
}

fn main() {
}