]>
Commit | Line | Data |
---|---|---|
136023e0 | 1 | // edition:2021 |
5869c6ff XL |
2 | // run-pass |
3 | ||
4 | // Test that we can mutate a place through a mut-borrow | |
5 | // that is captured by the closure | |
6 | ||
7 | // More specifically we test that the if the mutable reference isn't root variable of a capture | |
8 | // but rather accessed while acessing the precise capture. | |
9 | ||
5869c6ff XL |
10 | fn mut_tuple() { |
11 | let mut t = (10, 10); | |
12 | ||
13 | let t1 = (&mut t, 10); | |
14 | ||
15 | let mut c = || { | |
16 | // Mutable because (*t.0) is mutable | |
17 | t1.0.0 += 10; | |
18 | }; | |
19 | ||
20 | c(); | |
21 | } | |
22 | ||
23 | fn mut_tuple_nested() { | |
24 | let mut t = (10, 10); | |
25 | ||
26 | let t1 = (&mut t, 10); | |
27 | ||
28 | let mut c = || { | |
29 | let mut c = || { | |
30 | // Mutable because (*t.0) is mutable | |
31 | t1.0.0 += 10; | |
32 | }; | |
33 | ||
34 | c(); | |
35 | }; | |
36 | ||
37 | c(); | |
38 | } | |
39 | ||
40 | fn main() { | |
41 | mut_tuple(); | |
42 | mut_tuple_nested(); | |
43 | } |