2012-05-07 13:31:57 -05:00
|
|
|
fn use(_i: int) {}
|
|
|
|
|
|
|
|
fn foo() {
|
2012-05-30 12:46:22 -05:00
|
|
|
// Here, i is *moved* into the closure: Not actually OK
|
2012-05-07 13:31:57 -05:00
|
|
|
let mut i = 0;
|
2012-07-04 14:04:28 -05:00
|
|
|
do task::spawn {
|
2012-06-30 06:23:59 -05:00
|
|
|
use(i); //~ ERROR mutable variables cannot be implicitly captured
|
2012-05-07 13:31:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bar() {
|
|
|
|
// Here, i would be implicitly *copied* but it
|
|
|
|
// is mutable: bad
|
|
|
|
let mut i = 0;
|
|
|
|
while i < 10 {
|
2012-07-04 14:04:28 -05:00
|
|
|
do task::spawn {
|
2012-06-30 06:23:59 -05:00
|
|
|
use(i); //~ ERROR mutable variables cannot be implicitly captured
|
2012-05-07 13:31:57 -05:00
|
|
|
}
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn car() {
|
|
|
|
// Here, i is mutable, but *explicitly* copied:
|
|
|
|
let mut i = 0;
|
|
|
|
while i < 10 {
|
2012-06-30 18:19:07 -05:00
|
|
|
do task::spawn |copy i| {
|
2012-05-07 13:31:57 -05:00
|
|
|
use(i);
|
|
|
|
}
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2012-05-30 12:46:22 -05:00
|
|
|
}
|