]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-45157.rs
Rollup merge of #53104 - nivkner:unpin_doc, r=RalfJung
[rust.git] / src / test / ui / issues / issue-45157.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![allow(unused)]
12 #![feature(nll)]
13
14 #[derive(Clone, Copy, Default)]
15 struct S {
16     a: u8,
17     b: u8,
18 }
19 #[derive(Clone, Copy, Default)]
20 struct Z {
21     c: u8,
22     d: u8,
23 }
24
25 union U {
26     s: S,
27     z: Z,
28 }
29
30 fn main() {
31     unsafe {
32         let mut u = U { s: Default::default() };
33
34         let mref = &mut u.s.a;
35         *mref = 22;
36
37         let nref = &u.z.c;
38         //~^ ERROR cannot borrow `u.z.c` as immutable because it is also borrowed as mutable [E0502]
39         println!("{} {}", mref, nref)
40     }
41 }
42