|
10 | 10 |
|
11 | 11 | #![feature(unboxed_closures, overloaded_calls)]
|
12 | 12 |
|
| 13 | +// Tests that we can't assign to or mutably borrow upvars from `Fn` |
| 14 | +// closures (issue #17780) |
| 15 | + |
13 | 16 | fn set(x: &mut uint) { *x = 5; }
|
14 | 17 |
|
15 | 18 | fn main() {
|
16 | 19 | // By-ref captures
|
17 | 20 | {
|
18 | 21 | let mut x = 0u;
|
19 |
| - let _f = |&:| x = 42; |
20 |
| - //~^ ERROR cannot assign to data in a free |
21 |
| - // variable from an immutable unboxed closure |
| 22 | + let _f = |&:| x = 42; //~ ERROR cannot assign |
22 | 23 |
|
23 | 24 | let mut y = 0u;
|
24 |
| - let _g = |&:| set(&mut y); |
25 |
| - //~^ ERROR cannot borrow data mutably in a free |
26 |
| - // variable from an immutable unboxed closure |
| 25 | + let _g = |&:| set(&mut y); //~ ERROR cannot borrow |
27 | 26 |
|
28 | 27 | let mut z = 0u;
|
29 |
| - let _h = |&mut:| { set(&mut z); |&:| z = 42; }; |
30 |
| - //~^ ERROR cannot assign to data in a |
31 |
| - // free variable from an immutable unboxed closure |
| 28 | + let _h = |&mut:| { set(&mut z); |&:| z = 42; }; //~ ERROR cannot assign |
32 | 29 | }
|
33 | 30 | // By-value captures
|
34 | 31 | {
|
35 | 32 | let mut x = 0u;
|
36 |
| - let _f = move |&:| x = 42; |
37 |
| - //~^ ERROR cannot assign to data in a free |
38 |
| - // variable from an immutable unboxed closure |
| 33 | + let _f = move |&:| x = 42; //~ ERROR cannot assign |
39 | 34 |
|
40 | 35 | let mut y = 0u;
|
41 |
| - let _g = move |&:| set(&mut y); |
42 |
| - //~^ ERROR cannot borrow data mutably in a free |
43 |
| - // variable from an immutable unboxed closure |
| 36 | + let _g = move |&:| set(&mut y); //~ ERROR cannot borrow |
44 | 37 |
|
45 | 38 | let mut z = 0u;
|
46 |
| - let _h = move |&mut:| { set(&mut z); move |&:| z = 42; }; |
47 |
| - //~^ ERROR cannot assign to data in a free |
48 |
| - // variable from an immutable unboxed closure |
| 39 | + let _h = move |&mut:| { set(&mut z); move |&:| z = 42; }; //~ ERROR cannot assign |
49 | 40 | }
|
50 | 41 | }
|
0 commit comments