]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/2229_closure_analysis/multilevel-path-2.rs
Auto merge of #107843 - bjorn3:sync_cg_clif-2023-02-09, r=bjorn3
[rust.git] / tests / ui / closures / 2229_closure_analysis / multilevel-path-2.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     let c = #[rustc_capture_analysis]
18         //~^ ERROR: attributes on expressions are experimental
19         //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
20     || {
21     //~^ ERROR: First Pass analysis includes:
22     //~| ERROR: Min Capture analysis includes:
23         println!("{}", w.p.x);
24         //~^ NOTE: Capturing w[(0, 0),(0, 0)] -> ImmBorrow
25         //~| NOTE: Min Capture w[(0, 0),(0, 0)] -> ImmBorrow
26     };
27
28     // `c` only captures `w.p.x`, therefore it's safe to mutate `w.p.y`.
29     let py = &mut w.p.y;
30     c();
31
32     *py = 20
33 }