2018-01-24 07:14:58 -06:00
|
|
|
#![allow(unused)]
|
|
|
|
|
2018-12-24 13:22:25 -06:00
|
|
|
|
2018-01-24 07:14:58 -06:00
|
|
|
#[derive(Clone, Copy, Default)]
|
|
|
|
struct S {
|
|
|
|
a: u8,
|
|
|
|
b: u8,
|
|
|
|
}
|
|
|
|
#[derive(Clone, Copy, Default)]
|
|
|
|
struct Z {
|
|
|
|
c: u8,
|
|
|
|
d: u8,
|
|
|
|
}
|
|
|
|
|
|
|
|
union U {
|
|
|
|
s: S,
|
|
|
|
z: Z,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
unsafe {
|
|
|
|
let mut u = U { s: Default::default() };
|
|
|
|
|
|
|
|
let mref = &mut u.s.a;
|
|
|
|
*mref = 22;
|
|
|
|
|
|
|
|
let nref = &u.z.c;
|
2018-12-24 13:22:25 -06:00
|
|
|
//~^ ERROR cannot borrow `u` (via `u.z.c`) as immutable because it is also borrowed as mutable (via `u.s.a`) [E0502]
|
2018-01-24 07:14:58 -06:00
|
|
|
println!("{} {}", mref, nref)
|
|
|
|
}
|
|
|
|
}
|