Debian Codegraph @

.cargo/vendor/zerocopy-derive/tests/enum_known_layout.rs

raw
1 // Copyright 2023 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 // See comment in `include.rs` for why we disable the prelude.
10 #![no_implicit_prelude]
11 #![allow(warnings)]
12
13 include!("include.rs");
14
15 #[derive(imp::KnownLayout)]
16 enum Foo {
17 A,
18 }
19
20 util_assert_impl_all!(Foo: imp::KnownLayout);
21
22 #[derive(imp::KnownLayout)]
23 enum Bar {
24 A = 0,
25 }
26
27 util_assert_impl_all!(Bar: imp::KnownLayout);
28
29 #[derive(imp::KnownLayout)]
30 enum Baz {
31 A = 1,
32 B = 0,
33 }
34
35 util_assert_impl_all!(Baz: imp::KnownLayout);
36
37 // Deriving `KnownLayout` should work if the enum has bounded parameters.
38
39 #[derive(imp::KnownLayout)]
40 #[repr(C)]
41 enum WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::KnownLayout, const N: usize>
42 where
43 'a: 'b,
44 'b: 'a,
45 T: 'a + 'b + imp::KnownLayout,
46 {
47 Variant([T; N], imp::PhantomData<&'a &'b ()>),
48 }
49
50 util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::KnownLayout);