]> git.proxmox.com Git - rustc.git/blob - src/test/ui/closures/2229_closure_analysis/diagnostics/simple-struct-min-capture.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / src / test / ui / closures / 2229_closure_analysis / diagnostics / simple-struct-min-capture.rs
1 // edition:2021
2
3 // Test that borrow checker error is accurate and that min capture pass of the
4 // closure analysis is working as expected.
5
6 #[derive(Debug)]
7 struct Point {
8 x: i32,
9 y: i32,
10 }
11
12 fn main() {
13 let mut p = Point { x: 10, y: 20 };
14
15 // `p` is captured via mutable borrow.
16 let mut c = || {
17 p.x += 10;
18 println!("{:?}", p);
19 };
20
21
22 println!("{:?}", p);
23 //~^ ERROR: cannot borrow `p` as immutable because it is also borrowed as mutable
24 c();
25 }