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