| 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 zerocopy::KnownLayout; |
| 16 |
|
| 17 |
use self::util::AU16; |
| 18 |
|
| 19 |
fn main() {} |
| 20 |
|
| 21 |
// |
| 22 |
// KnownLayout errors |
| 23 |
// |
| 24 |
|
| 25 |
struct NotKnownLayout; |
| 26 |
|
| 27 |
struct NotKnownLayoutDst([u8]); |
| 28 |
|
| 29 |
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name | |
| 30 |
// | N | N | N | N | KL00 | |
| 31 |
#[derive(KnownLayout)] |
| 32 |
struct KL00(u8, NotKnownLayoutDst); |
| 33 |
|
| 34 |
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name | |
| 35 |
// | N | N | Y | N | KL02 | |
| 36 |
#[derive(KnownLayout)] |
| 37 |
struct KL02(u8, [u8]); |
| 38 |
|
| 39 |
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name | |
| 40 |
// | Y | N | N | N | KL08 | |
| 41 |
#[derive(KnownLayout)] |
| 42 |
#[repr(C)] |
| 43 |
struct KL08(u8, NotKnownLayoutDst); |
| 44 |
|
| 45 |
// | `repr(C)`? | generic? | `KnownLayout`? | `Sized`? | Type Name | |
| 46 |
// | Y | N | N | Y | KL09 | |
| 47 |
#[derive(KnownLayout)] |
| 48 |
#[repr(C)] |
| 49 |
struct KL09(NotKnownLayout, NotKnownLayout); |
| 50 |
|
| 51 |
// |
| 52 |
// AsBytes errors |
| 53 |
// |
| 54 |
|
| 55 |
#[derive(AsBytes)] |
| 56 |
#[repr(C)] |
| 57 |
struct AsBytes1<T>(T); |
| 58 |
|
| 59 |
#[derive(AsBytes)] |
| 60 |
#[repr(C)] |
| 61 |
struct AsBytes2 { |
| 62 |
foo: u8, |
| 63 |
bar: AU16, |
| 64 |
} |
| 65 |
|
| 66 |
#[derive(AsBytes)] |
| 67 |
#[repr(C, packed(2))] |
| 68 |
struct AsBytes3 { |
| 69 |
foo: u8, |
| 70 |
// We'd prefer to use AU64 here, but you can't use aligned types in |
| 71 |
// packed structs. |
| 72 |
bar: u64, |
| 73 |
} |
| 74 |
|
| 75 |
// |
| 76 |
// Unaligned errors |
| 77 |
// |
| 78 |
|
| 79 |
#[derive(Unaligned)] |
| 80 |
#[repr(C, align(2))] |
| 81 |
struct Unaligned1; |
| 82 |
|
| 83 |
#[derive(Unaligned)] |
| 84 |
#[repr(transparent, align(2))] |
| 85 |
struct Unaligned2 { |
| 86 |
foo: u8, |
| 87 |
} |
| 88 |
|
| 89 |
#[derive(Unaligned)] |
| 90 |
#[repr(packed, align(2))] |
| 91 |
struct Unaligned3; |
| 92 |
|
| 93 |
#[derive(Unaligned)] |
| 94 |
#[repr(align(1), align(2))] |
| 95 |
struct Unaligned4; |
| 96 |
|
| 97 |
#[derive(Unaligned)] |
| 98 |
#[repr(align(2), align(4))] |
| 99 |
struct Unaligned5; |