Debian Codegraph @

third_party/rust/zerocopy-derive/tests/enum_known_layout.rs

raw
1 // Copyright 2022 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #![allow(warnings)]
6
7 mod util;
8
9 use {core::marker::PhantomData, static_assertions::assert_impl_all, zerocopy::KnownLayout};
10
11 #[derive(KnownLayout)]
12 enum Foo {
13 A,
14 }
15
16 assert_impl_all!(Foo: KnownLayout);
17
18 #[derive(KnownLayout)]
19 enum Bar {
20 A = 0,
21 }
22
23 assert_impl_all!(Bar: KnownLayout);
24
25 #[derive(KnownLayout)]
26 enum Baz {
27 A = 1,
28 B = 0,
29 }
30
31 assert_impl_all!(Baz: KnownLayout);
32
33 // Deriving `KnownLayout` should work if the enum has bounded parameters.
34
35 #[derive(KnownLayout)]
36 #[repr(C)]
37 enum WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + KnownLayout>
38 where
39 'a: 'b,
40 'b: 'a,
41 T: 'a + 'b + KnownLayout,
42 {
43 Variant([T; N], PhantomData<&'a &'b ()>),
44 }
45
46 assert_impl_all!(WithParams<'static, 'static, 42, u8>: KnownLayout);