]> git.proxmox.com Git - rustc.git/blob - tests/ui/borrowck/borrowck-union-borrow-nested.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / borrowck / borrowck-union-borrow-nested.rs
1 #[derive(Clone, Copy)]
2 struct S {
3 a: u8,
4 b: u16,
5 }
6
7 #[derive(Clone, Copy)]
8 union U {
9 s: S,
10 c: u32,
11 }
12
13 fn main() {
14 unsafe {
15 {
16 let mut u = U { s: S { a: 0, b: 1 } };
17 let ra = &mut u.s.a;
18 let b = u.s.b; // OK
19 ra.use_mut();
20 }
21 {
22 let mut u = U { s: S { a: 0, b: 1 } };
23 let ra = &mut u.s.a;
24 let b = u.c; //~ ERROR cannot use `u.c` because it was mutably borrowed
25 ra.use_mut();
26 }
27 }
28 }
29
30 trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
31 impl<T> Fake for T { }