2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-08-14 14:53:45 -05:00
|
|
|
fn user(_i: int) {}
|
2012-05-07 13:31:57 -05:00
|
|
|
|
|
|
|
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-08-14 14:53:45 -05:00
|
|
|
user(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-08-14 17:15:15 -05:00
|
|
|
user(i); //~ ERROR mutable variables cannot be implicitly captured
|
2012-05-07 13:31:57 -05:00
|
|
|
}
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn car() {
|
2013-01-10 12:59:58 -06:00
|
|
|
// Here, i is mutable, but *explicitly* shadowed copied:
|
2012-05-07 13:31:57 -05:00
|
|
|
let mut i = 0;
|
|
|
|
while i < 10 {
|
2013-01-10 12:59:58 -06:00
|
|
|
{
|
|
|
|
let i = i;
|
|
|
|
do task::spawn {
|
|
|
|
user(i);
|
|
|
|
}
|
2012-05-07 13:31:57 -05:00
|
|
|
}
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2012-05-30 12:46:22 -05:00
|
|
|
}
|