• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(Clone, Copy, imp::KnownLayout)]
16 union Zst {
17     a: (),
18 }
19 
20 util_assert_impl_all!(Zst: imp::KnownLayout);
21 
22 #[derive(imp::KnownLayout)]
23 union One {
24     a: bool,
25 }
26 
27 util_assert_impl_all!(One: imp::KnownLayout);
28 
29 #[derive(imp::KnownLayout)]
30 union Two {
31     a: bool,
32     b: Zst,
33 }
34 
35 util_assert_impl_all!(Two: imp::KnownLayout);
36 
37 #[derive(imp::KnownLayout)]
38 union TypeParams<'a, T: imp::Copy, I: imp::Iterator>
39 where
40     I::Item: imp::Copy,
41 {
42     a: T,
43     c: I::Item,
44     d: u8,
45     e: imp::PhantomData<&'a [u8]>,
46     f: imp::PhantomData<&'static str>,
47     g: imp::PhantomData<imp::String>,
48 }
49 
50 util_assert_impl_all!(TypeParams<'static, (), imp::IntoIter<()>>: imp::KnownLayout);
51 
52 // Deriving `imp::KnownLayout` should work if the union has bounded parameters.
53 
54 #[derive(imp::KnownLayout)]
55 #[repr(C)]
56 union WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::KnownLayout, const N: usize>
57 where
58     'a: 'b,
59     'b: 'a,
60     T: 'a + 'b + imp::Copy + imp::KnownLayout,
61 {
62     a: [T; N],
63     b: imp::PhantomData<&'a &'b ()>,
64 }
65 
66 util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::KnownLayout);
67