diff options
Diffstat (limited to 'tests/ui-stable/derive_transparent.rs')
-rw-r--r-- | tests/ui-stable/derive_transparent.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/ui-stable/derive_transparent.rs b/tests/ui-stable/derive_transparent.rs new file mode 100644 index 0000000..a99f92c --- /dev/null +++ b/tests/ui-stable/derive_transparent.rs @@ -0,0 +1,36 @@ +// Copyright 2019 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +extern crate zerocopy; + +#[path = "../util.rs"] +mod util; + +use core::marker::PhantomData; + +use { + static_assertions::assert_impl_all, + zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned}, +}; + +use self::util::NotZerocopy; + +fn main() {} + +// Test generic transparent structs + +#[derive(AsBytes, FromZeroes, FromBytes, Unaligned)] +#[repr(transparent)] +struct TransparentStruct<T> { + inner: T, + _phantom: PhantomData<()>, +} + +// It should be legal to derive these traits on a transparent struct, but it +// must also ensure the traits are only implemented when the inner type +// implements them. +assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeroes); +assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes); +assert_impl_all!(TransparentStruct<NotZerocopy>: AsBytes); +assert_impl_all!(TransparentStruct<NotZerocopy>: Unaligned); |