diff options
| author | David Wood <david@davidtw.co> | 2018-01-24 13:14:58 +0000 |
|---|---|---|
| committer | David Wood <david@davidtw.co> | 2018-01-24 18:36:34 +0000 |
| commit | e6376a15b4f22bc296a832d232937add7e04511d (patch) | |
| tree | 20a9897f3d2162db8c8465bb37c5964a0bf41e0a | |
| parent | 3a39b2aa5a68dd07aacab2106db3927f666a485a (diff) | |
| download | rust-e6376a15b4f22bc296a832d232937add7e04511d.tar.gz rust-e6376a15b4f22bc296a832d232937add7e04511d.zip | |
Added test for #45157
| -rw-r--r-- | src/test/ui/issue-45157.rs | 43 | ||||
| -rw-r--r-- | src/test/ui/issue-45157.stderr | 20 |
2 files changed, 63 insertions, 0 deletions
diff --git a/src/test/ui/issue-45157.rs b/src/test/ui/issue-45157.rs new file mode 100644 index 00000000000..cff338f76c5 --- /dev/null +++ b/src/test/ui/issue-45157.rs @@ -0,0 +1,43 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(unused)] +#![feature(nll)] + +#[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; + //~^ ERROR cannot borrow `u.z.c` as immutable because it is also borrowed as mutable [E0502] + println!("{} {}", mref, nref) + //~^ ERROR cannot borrow `u.s.a` as mutable because it is also borrowed as immutable [E0502] + } +} + diff --git a/src/test/ui/issue-45157.stderr b/src/test/ui/issue-45157.stderr new file mode 100644 index 00000000000..e133aab31bc --- /dev/null +++ b/src/test/ui/issue-45157.stderr @@ -0,0 +1,20 @@ +error[E0502]: cannot borrow `u.z.c` as immutable because it is also borrowed as mutable + --> $DIR/issue-45157.rs:37:20 + | +34 | let mref = &mut u.s.a; + | ---------- mutable borrow occurs here +... +37 | let nref = &u.z.c; + | ^^^^^^ immutable borrow occurs here + +error[E0502]: cannot borrow `u.s.a` as mutable because it is also borrowed as immutable + --> $DIR/issue-45157.rs:39:27 + | +37 | let nref = &u.z.c; + | ------ immutable borrow occurs here +38 | //~^ ERROR cannot borrow `u.z.c` as immutable because it is also borrowed as mutable [E0502] +39 | println!("{} {}", mref, nref) + | ^^^^ mutable borrow occurs here + +error: aborting due to 2 previous errors + |
