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 = "../util.rs"]
13 mod util;
14
15 use self::util::AU16;
16 use std::mem::ManuallyDrop;
17
main()18 fn main() {}
19
20 //
21 // AsBytes errors
22 //
23
24 #[derive(AsBytes)]
25 #[repr(C)]
26 union AsBytes1<T> {
27 foo: ManuallyDrop<T>,
28 }
29
30 #[derive(AsBytes)]
31 #[repr(C)]
32 union AsBytes2 {
33 foo: u8,
34 bar: [u8; 2],
35 }
36
37 //
38 // Unaligned errors
39 //
40
41 #[derive(Unaligned)]
42 #[repr(C, align(2))]
43 union Unaligned1 {
44 foo: i16,
45 bar: AU16,
46 }
47
48 // Transparent unions are unstable; see issue #60405
49 // <https://github.com/rust-lang/rust/issues/60405> for more information.
50
51 // #[derive(Unaligned)]
52 // #[repr(transparent, align(2))]
53 // union Unaligned2 {
54 // foo: u8,
55 // }
56
57 #[derive(Unaligned)]
58 #[repr(packed, align(2))]
59 union Unaligned3 {
60 foo: u8,
61 }
62
63 #[derive(Unaligned)]
64 #[repr(align(1), align(2))]
65 struct Unaligned4 {
66 foo: u8,
67 }
68
69 #[derive(Unaligned)]
70 #[repr(align(2), align(4))]
71 struct Unaligned5 {
72 foo: u8,
73 }
74