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::NotZerocopy, util::AU16};
16 use zerocopy::KnownLayout;
17
main()18 fn main() {}
19
20 // These tests cause errors which are generated by a later compilation pass than
21 // the other errors we generate, and so if they're compiled in the same file,
22 // the compiler will never get to that pass, and so we won't get the errors.
23
24 //
25 // TryFromBytes errors
26 //
27
28 #[derive(TryFromBytes)]
29 struct TryFromBytes1 {
30 value: NotZerocopy,
31 }
32
33 //
34 // FromZeros errors
35 //
36
37 #[derive(FromZeros)]
38 struct FromZeros1 {
39 value: NotZerocopy,
40 }
41
42 //
43 // FromBytes errors
44 //
45
46 #[derive(FromBytes)]
47 struct FromBytes1 {
48 value: NotZerocopy,
49 }
50
51 //
52 // IntoBytes errors
53 //
54
55 #[derive(IntoBytes)]
56 #[repr(C)]
57 struct IntoBytes1 {
58 value: NotZerocopy,
59 }
60
61 //
62 // Unaligned errors
63 //
64
65 #[derive(Unaligned)]
66 #[repr(C)]
67 struct Unaligned1 {
68 aligned: AU16,
69 }
70
71 // This specifically tests a bug we had in an old version of the code in which
72 // the trait bound would only be enforced for the first field's type.
73 #[derive(Unaligned)]
74 #[repr(C)]
75 struct Unaligned2 {
76 unaligned: u8,
77 aligned: AU16,
78 }
79
80 #[derive(Unaligned)]
81 #[repr(transparent)]
82 struct Unaligned3 {
83 aligned: AU16,
84 }
85