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