]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/2229_closure_analysis/multilevel-path-1.rs
Auto merge of #105716 - chriswailes:ndk-update-redux, r=pietroalbini
[rust.git] / tests / ui / closures / 2229_closure_analysis / multilevel-path-1.rs
1 // edition:2021
2
3 #![feature(rustc_attrs)]
4 #![allow(unused)]
5
6 struct Point {
7     x: i32,
8     y: i32,
9 }
10 struct Wrapper {
11     p: Point,
12 }
13
14 fn main() {
15     let mut w = Wrapper { p: Point { x: 10, y: 10 } };
16
17     // Only paths that appears within the closure that directly start off
18     // a variable defined outside the closure are captured.
19     //
20     // Therefore `w.p` is captured
21     // Note that `wp.x` doesn't start off a variable defined outside the closure.
22     let c = #[rustc_capture_analysis]
23     //~^ ERROR: attributes on expressions are experimental
24     //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
25     || {
26     //~^ ERROR: First Pass analysis includes:
27     //~| ERROR: Min Capture analysis includes:
28         let wp = &w.p;
29         //~^ NOTE: Capturing w[(0, 0)] -> ImmBorrow
30         //~| NOTE: Min Capture w[(0, 0)] -> ImmBorrow
31         println!("{}", wp.x);
32     };
33
34     // Since `c` captures `w.p` by an ImmBorrow, `w.p.y` can't be mutated.
35     let py = &mut w.p.y;
36     c();
37
38     *py = 20
39 }