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