Debian Codegraph @

debian/rust-vendor/zerocopy-derive/tests/ui/derive_transparent.rs

raw
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 extern crate zerocopy_renamed;
10
11 #[path = "../include.rs"]
12 mod util;
13
14 use core::marker::PhantomData;
15
16 use zerocopy_renamed::{FromBytes, FromZeros, IntoBytes, TryFromBytes, Unaligned};
17
18 use self::util::util::NotZerocopy;
19
20 fn main() {}
21
22 // Test generic transparent structs
23
24 #[derive(IntoBytes, FromBytes, Unaligned)]
25 #[zerocopy(crate = "zerocopy_renamed")]
26 #[repr(transparent)]
27 struct TransparentStruct<T> {
28 inner: T,
29 _phantom: PhantomData<()>,
30 }
31
32 // It should be legal to derive these traits on a transparent struct, but it
33 // must also ensure the traits are only implemented when the inner type
34 // implements them.
35 util_assert_impl_all!(TransparentStruct<NotZerocopy>: TryFromBytes);
36 //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::TryFromBytes` is not satisfied
37
38 util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeros);
39 //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: FromZeros` is not satisfied
40
41 util_assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
42 //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::FromBytes` is not satisfied
43
44 util_assert_impl_all!(TransparentStruct<NotZerocopy>: IntoBytes);
45 //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::IntoBytes` is not satisfied
46
47 util_assert_impl_all!(TransparentStruct<NotZerocopy>: Unaligned);
48 //~[msrv, stable, nightly]^ ERROR: the trait bound `NotZerocopy: zerocopy_renamed::Unaligned` is not satisfied