4 // This tests the error messages for borrows of union fields when the unions are embedded in other
7 #[derive(Clone, Copy, Default)]
13 #[derive(Clone, Copy)]
20 #[derive(Clone, Copy)]
31 // Borrow a different field of the nested union.
36 r2_union: First { f3_union: Second { s2_leaf: Leaf { l1_u8: 8, l2_u8: 4 } } }
39 let mref = &mut r.r2_union.f3_union.s1_leaf.l1_u8;
42 let nref = &r.r2_union.f3_union.s2_leaf.l1_u8;
44 //~^^ 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]
45 println!("{} {}", mref, nref)
49 // Borrow a different field of the first union.
54 r2_union: First { f3_union: Second { s2_leaf: Leaf { l1_u8: 8, l2_u8: 4 } } }
57 let mref = &mut r.r2_union.f2_leaf.l1_u8;
60 let nref = &r.r2_union.f1_leaf.l1_u8;
62 //~^^ 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]
63 println!("{} {}", mref, nref)