1 // Copyright 2019 The Fuchsia Authors
2 //
3 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
4 // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
5 // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
6 // This file may not be copied, modified, or distributed except according to
7 // those terms.
8
9 #[macro_use]
10 extern crate zerocopy;
11
12 #[path = "../include.rs"]
13 mod util;
14
15 use self::util::util::AU16;
16 use std::mem::ManuallyDrop;
17
main()18 fn main() {}
19
20 //
21 // Immutable errors
22 //
23
24 #[derive(Immutable)]
25 union Immutable1 {
26 a: ManuallyDrop<core::cell::UnsafeCell<()>>,
27 }
28
29 //
30 // IntoBytes errors
31 //
32
33 #[derive(IntoBytes)]
34 #[repr(C)]
35 union IntoBytes1<T> {
36 foo: ManuallyDrop<T>,
37 }
38
39 #[derive(IntoBytes)]
40 #[repr(C)]
41 union IntoBytes2 {
42 foo: u8,
43 bar: [u8; 2],
44 }
45
46 // Need a `repr` attribute
47 #[derive(IntoBytes)]
48 union IntoBytes3 {
49 foo: u8,
50 }
51
52 // `repr(packed(2))` isn't equivalent to `repr(packed)`
53 #[derive(IntoBytes)]
54 #[repr(packed(2))]
55 union IntoBytes4 {
56 foo: u8,
57 }
58
59 //
60 // Unaligned errors
61 //
62
63 #[derive(Unaligned)]
64 #[repr(C, align(2))]
65 union Unaligned1 {
66 foo: i16,
67 bar: AU16,
68 }
69
70 // Transparent unions are unstable; see issue #60405
71 // <https://github.com/rust-lang/rust/issues/60405> for more information.
72
73 // #[derive(Unaligned)]
74 // #[repr(transparent, align(2))]
75 // union Unaligned2 {
76 // foo: u8,
77 // }
78
79 #[derive(Unaligned)]
80 #[repr(packed, align(2))]
81 union Unaligned3 {
82 foo: u8,
83 }
84
85 #[derive(Unaligned)]
86 #[repr(align(1), align(2))]
87 struct Unaligned4 {
88 foo: u8,
89 }
90
91 #[derive(Unaligned)]
92 #[repr(align(2), align(4))]
93 struct Unaligned5 {
94 foo: u8,
95 }
96
97 #[derive(Unaligned)]
98 union Unaligned6 {
99 foo: i16,
100 bar: AU16,
101 }
102
103 #[derive(Unaligned)]
104 #[repr(packed(2))]
105 union Unaligned7 {
106 foo: i16,
107 bar: AU16,
108 }
109