3 // ignore-tidy-linelength
5 // This tests the error messages for borrows of union fields when the unions are embedded in other
8 #[derive(Clone, Copy, Default)]
14 #[derive(Clone, Copy)]
21 #[derive(Clone, Copy)]
32 // Borrow a different field of the nested union.
37 r2_union: First { f3_union: Second { s2_leaf: Leaf { l1_u8: 8, l2_u8: 4 } } }
40 let mref = &mut r.r2_union.f3_union.s1_leaf.l1_u8;
43 let nref = &r.r2_union.f3_union.s2_leaf.l1_u8;
45 //~^^ ERROR cannot borrow `r.r2_union.f3_union` (via `r.r2_union.f3_union.s2_leaf.l1_u8`) as immutable because it is also borrowed as mutable (via `r.r2_union.f3_union.s1_leaf.l1_u8`) [E0502]
46 println!("{} {}", mref, nref)
50 // Borrow a different field of the first union.
55 r2_union: First { f3_union: Second { s2_leaf: Leaf { l1_u8: 8, l2_u8: 4 } } }
58 let mref = &mut r.r2_union.f2_leaf.l1_u8;
61 let nref = &r.r2_union.f1_leaf.l1_u8;
63 //~^^ ERROR cannot borrow `r.r2_union` (via `r.r2_union.f1_leaf.l1_u8`) as immutable because it is also borrowed as mutable (via `r.r2_union.f2_leaf.l1_u8`) [E0502]
64 println!("{} {}", mref, nref)