| 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 std::mem::ManuallyDrop; |
| 16 |
|
| 17 |
use self::util::util::AU16; |
| 18 |
|
| 19 |
fn main() {} |
| 20 |
|
| 21 |
// |
| 22 |
// Immutable errors |
| 23 |
// |
| 24 |
|
| 25 |
#[derive(Immutable)] |
| 26 |
union Immutable1 { |
| 27 |
a: ManuallyDrop<core::cell::UnsafeCell<()>>, |
| 28 |
} |
| 29 |
|
| 30 |
// |
| 31 |
// IntoBytes errors |
| 32 |
// |
| 33 |
|
| 34 |
#[derive(IntoBytes)] |
| 35 |
#[repr(C)] |
| 36 |
union IntoBytes1<T> { |
| 37 |
foo: ManuallyDrop<T>, |
| 38 |
} |
| 39 |
|
| 40 |
#[derive(IntoBytes)] |
| 41 |
#[repr(C)] |
| 42 |
union IntoBytes2 { |
| 43 |
foo: u8, |
| 44 |
bar: [u8; 2], |
| 45 |
} |
| 46 |
|
| 47 |
// Need a `repr` attribute |
| 48 |
#[derive(IntoBytes)] |
| 49 |
union IntoBytes3 { |
| 50 |
foo: u8, |
| 51 |
} |
| 52 |
|
| 53 |
// `repr(packed(2))` isn't equivalent to `repr(packed)` |
| 54 |
#[derive(IntoBytes)] |
| 55 |
#[repr(packed(2))] |
| 56 |
union IntoBytes4 { |
| 57 |
foo: u8, |
| 58 |
} |
| 59 |
|
| 60 |
// |
| 61 |
// Unaligned errors |
| 62 |
// |
| 63 |
|
| 64 |
#[derive(Unaligned)] |
| 65 |
#[repr(C, align(2))] |
| 66 |
union Unaligned1 { |
| 67 |
foo: i16, |
| 68 |
bar: AU16, |
| 69 |
} |
| 70 |
|
| 71 |
// Transparent unions are unstable; see issue #60405 |
| 72 |
// <https://github.com/rust-lang/rust/issues/60405> for more information. |
| 73 |
|
| 74 |
// #[derive(Unaligned)] |
| 75 |
// #[repr(transparent, align(2))] |
| 76 |
// union Unaligned2 { |
| 77 |
// foo: u8, |
| 78 |
// } |
| 79 |
|
| 80 |
#[derive(Unaligned)] |
| 81 |
#[repr(packed, align(2))] |
| 82 |
union Unaligned3 { |
| 83 |
foo: u8, |
| 84 |
} |
| 85 |
|
| 86 |
#[derive(Unaligned)] |
| 87 |
#[repr(align(1), align(2))] |
| 88 |
struct Unaligned4 { |
| 89 |
foo: u8, |
| 90 |
} |
| 91 |
|
| 92 |
#[derive(Unaligned)] |
| 93 |
#[repr(align(2), align(4))] |
| 94 |
struct Unaligned5 { |
| 95 |
foo: u8, |
| 96 |
} |
| 97 |
|
| 98 |
#[derive(Unaligned)] |
| 99 |
union Unaligned6 { |
| 100 |
foo: i16, |
| 101 |
bar: AU16, |
| 102 |
} |
| 103 |
|
| 104 |
#[derive(Unaligned)] |
| 105 |
#[repr(packed(2))] |
| 106 |
union Unaligned7 { |
| 107 |
foo: i16, |
| 108 |
bar: AU16, |
| 109 |
} |