]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/2229_closure_analysis/capture-disjoint-field-struct.rs
Auto merge of #107843 - bjorn3:sync_cg_clif-2023-02-09, r=bjorn3
[rust.git] / tests / ui / closures / 2229_closure_analysis / capture-disjoint-field-struct.rs
1 // edition:2021
2
3 #![feature(rustc_attrs)]
4
5 struct Point {
6     x: i32,
7     y: i32,
8 }
9
10 fn main() {
11     let mut p = Point { x: 10, y: 10 };
12
13     let c = #[rustc_capture_analysis]
14     //~^ ERROR: attributes on expressions are experimental
15     //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
16     || {
17     //~^ First Pass analysis includes:
18     //~| Min Capture analysis includes:
19         println!("{}", p.x);
20         //~^ NOTE: Capturing p[(0, 0)] -> ImmBorrow
21         //~| NOTE: Min Capture p[(0, 0)] -> ImmBorrow
22     };
23
24     // `c` should only capture `p.x`, therefore mutating `p.y` is allowed.
25     let py = &mut p.y;
26
27     c();
28     *py = 20;
29 }