]>
Commit | Line | Data |
---|---|---|
136023e0 | 1 | // edition:2021 |
fc512014 | 2 | |
fc512014 XL |
3 | #![feature(rustc_attrs)] |
4 | ||
5 | struct Point { | |
6 | x: i32, | |
7 | y: i32, | |
8 | } | |
9 | ||
10 | // This testcase ensures that nested closures are handles properly | |
11 | // - The nested closure is analyzed first. | |
12 | // - The capture kind of the nested closure is accounted for by the enclosing closure | |
13 | // - Any captured path by the nested closure that starts off a local variable in the enclosing | |
14 | // closure is not listed as a capture of the enclosing closure. | |
15 | ||
16 | fn main() { | |
17 | let mut p = Point { x: 5, y: 20 }; | |
18 | ||
19 | let mut c1 = #[rustc_capture_analysis] | |
20 | //~^ ERROR: attributes on expressions are experimental | |
21 | //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> | |
22 | || { | |
23 | //~^ ERROR: First Pass analysis includes: | |
24 | //~| ERROR: Min Capture analysis includes: | |
25 | println!("{}", p.x); | |
26 | //~^ NOTE: Capturing p[(0, 0)] -> ImmBorrow | |
27 | //~| NOTE: Min Capture p[(0, 0)] -> ImmBorrow | |
28 | let incr = 10; | |
29 | let mut c2 = #[rustc_capture_analysis] | |
30 | //~^ ERROR: attributes on expressions are experimental | |
31 | //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> | |
32 | || p.y += incr; | |
33 | //~^ ERROR: First Pass analysis includes: | |
34 | //~| ERROR: Min Capture analysis includes: | |
35 | //~| NOTE: Capturing p[(1, 0)] -> MutBorrow | |
36 | //~| NOTE: Capturing incr[] -> ImmBorrow | |
37 | //~| NOTE: Min Capture p[(1, 0)] -> MutBorrow | |
38 | //~| NOTE: Min Capture incr[] -> ImmBorrow | |
39 | //~| NOTE: Capturing p[(1, 0)] -> MutBorrow | |
40 | //~| NOTE: Min Capture p[(1, 0)] -> MutBorrow | |
41 | c2(); | |
42 | println!("{}", p.y); | |
43 | }; | |
44 | ||
45 | c1(); | |
46 | ||
47 | let px = &p.x; | |
48 | ||
49 | println!("{}", px); | |
50 | ||
51 | c1(); | |
52 | } |