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