]> git.lizzy.rs Git - rust.git/blob - src/test/ui/union/union-borrow-move-parent-sibling.rs
Auto merge of #60039 - rasendubi:assert-trailing-junk, r=alexcrichton
[rust.git] / src / test / ui / union / union-borrow-move-parent-sibling.rs
1 #![feature(untagged_unions)]
2 #![allow(unused)]
3
4 #[allow(unions_with_drop_fields)]
5 union U {
6     x: ((Vec<u8>, Vec<u8>), Vec<u8>),
7     y: Box<Vec<u8>>,
8 }
9
10 fn use_borrow<T>(_: &T) {}
11
12 unsafe fn parent_sibling_borrow() {
13     let mut u = U { x: ((Vec::new(), Vec::new()), Vec::new()) };
14     let a = &mut u.x.0;
15     let b = &u.y; //~ ERROR cannot borrow `u` (via `u.y`)
16     use_borrow(a);
17 }
18
19 unsafe fn parent_sibling_move() {
20     let u = U { x: ((Vec::new(), Vec::new()), Vec::new()) };
21     let a = u.x.0;
22     let b = u.y; //~ ERROR use of moved value: `u`
23 }
24
25 unsafe fn grandparent_sibling_borrow() {
26     let mut u = U { x: ((Vec::new(), Vec::new()), Vec::new()) };
27     let a = &mut (u.x.0).0;
28     let b = &u.y; //~ ERROR cannot borrow `u` (via `u.y`)
29     use_borrow(a);
30 }
31
32 unsafe fn grandparent_sibling_move() {
33     let u = U { x: ((Vec::new(), Vec::new()), Vec::new()) };
34     let a = (u.x.0).0;
35     let b = u.y; //~ ERROR use of moved value: `u`
36 }
37
38 unsafe fn deref_sibling_borrow() {
39     let mut u = U { y: Box::default() };
40     let a = &mut *u.y;
41     let b = &u.x; //~ ERROR cannot borrow `u` (via `u.x`)
42     use_borrow(a);
43 }
44
45 unsafe fn deref_sibling_move() {
46     let u = U { x: ((Vec::new(), Vec::new()), Vec::new()) };
47     let a = *u.y;
48     let b = u.x; //~ ERROR use of moved value: `u`
49 }
50
51
52 fn main() {}