4 // ignore-tidy-linelength
6 // This tests the error messages for borrows of union fields when the unions are embedded in other
9 #[derive(Clone, Copy, Default)]
15 #[derive(Clone, Copy)]
22 #[derive(Clone, Copy)]
33 // Borrow a different field of the nested union.
38 r2_union: First { f3_union: Second { s2_leaf: Leaf { l1_u8: 8, l2_u8: 4 } } }
41 let mref = &mut r.r2_union.f3_union.s1_leaf.l1_u8;
44 let nref = &r.r2_union.f3_union.s2_leaf.l1_u8;
46 //~^^ 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]
47 println!("{} {}", mref, nref)
51 // Borrow a different field of the first union.
56 r2_union: First { f3_union: Second { s2_leaf: Leaf { l1_u8: 8, l2_u8: 4 } } }
59 let mref = &mut r.r2_union.f2_leaf.l1_u8;
62 let nref = &r.r2_union.f1_leaf.l1_u8;
64 //~^^ 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]
65 println!("{} {}", mref, nref)