]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/2229_closure_analysis/diagnostics/union.rs
Rollup merge of #107282 - BoxyUwU:erica_builtin_pointee_impls, r=compiler-errors
[rust.git] / tests / ui / closures / 2229_closure_analysis / diagnostics / union.rs
1 // edition:2021
2
3 // Test that we point to the correct location that results a union being captured.
4 // Union is special because it can't be disjointly captured.
5
6 union A {
7     y: u32,
8     x: (),
9 }
10
11 fn main() {
12     let mut a = A { y: 1 };
13     let mut c = || {
14     //~^ `a.y` is borrowed here
15         let _ = unsafe { &a.y };
16         let _ = &mut a;
17         //~^ borrow occurs due to use in closure
18         let _ = unsafe { &mut a.y };
19     };
20     a.y = 1;
21     //~^ cannot assign to `a.y` because it is borrowed [E0506]
22     //~| `a.y` is assigned to here
23     c();
24     //~^ borrow later used here
25 }