]>
Commit | Line | Data |
---|---|---|
416331ca XL |
1 | // run-pass |
2 | ||
0bf4aa26 XL |
3 | #![allow(unused_must_use)] |
4 | #![allow(dead_code)] | |
c34b1796 AL |
5 | use std::thread; |
6 | ||
7 | fn user(_i: isize) {} | |
1a4d82fc JJ |
8 | |
9 | fn foo() { | |
10 | // Here, i is *copied* into the proc (heap closure). | |
11 | // Requires allocation. The proc's copy is not mutable. | |
12 | let mut i = 0; | |
9346a6ac | 13 | let t = thread::spawn(move|| { |
1a4d82fc JJ |
14 | user(i); |
15 | println!("spawned {}", i) | |
16 | }); | |
17 | i += 1; | |
9346a6ac AL |
18 | println!("original {}", i); |
19 | t.join(); | |
1a4d82fc JJ |
20 | } |
21 | ||
22 | fn bar() { | |
23 | // Here, the original i has not been moved, only copied, so is still | |
24 | // mutable outside of the proc. | |
25 | let mut i = 0; | |
26 | while i < 10 { | |
9346a6ac | 27 | let t = thread::spawn(move|| { |
1a4d82fc JJ |
28 | user(i); |
29 | }); | |
30 | i += 1; | |
9346a6ac | 31 | t.join(); |
1a4d82fc JJ |
32 | } |
33 | } | |
34 | ||
35 | fn car() { | |
36 | // Here, i must be shadowed in the proc to be mutable. | |
37 | let mut i = 0; | |
38 | while i < 10 { | |
9346a6ac | 39 | let t = thread::spawn(move|| { |
1a4d82fc JJ |
40 | let mut i = i; |
41 | i += 1; | |
42 | user(i); | |
43 | }); | |
44 | i += 1; | |
9346a6ac | 45 | t.join(); |
1a4d82fc JJ |
46 | } |
47 | } | |
48 | ||
49 | pub fn main() {} |