Debian Codegraph @

.cargo/vendor/zerocopy-derive/tests/struct_no_cell.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::Immutable)]
16 struct Zst;
17
18 util_assert_impl_all!(Zst: imp::Immutable);
19
20 #[derive(imp::Immutable)]
21 struct One {
22 a: bool,
23 }
24
25 util_assert_impl_all!(One: imp::Immutable);
26
27 #[derive(imp::Immutable)]
28 struct Two {
29 a: bool,
30 b: Zst,
31 }
32
33 util_assert_impl_all!(Two: imp::Immutable);
34
35 #[derive(imp::Immutable)]
36 struct Three {
37 a: [u8],
38 }
39
40 util_assert_impl_all!(Three: imp::Immutable);
41
42 #[derive(imp::Immutable)]
43 struct Four<'a> {
44 field: &'a imp::UnsafeCell<u8>,
45 }
46
47 util_assert_impl_all!(Four<'static>: imp::Immutable);
48
49 #[derive(imp::Immutable)]
50 struct TypeParams<'a, T, U, I: imp::Iterator> {
51 a: I::Item,
52 b: u8,
53 c: imp::PhantomData<&'a [::core::primitive::u8]>,
54 d: imp::PhantomData<&'static ::core::primitive::str>,
55 e: imp::PhantomData<imp::String>,
56 f: imp::PhantomData<U>,
57 g: T,
58 }
59
60 util_assert_impl_all!(TypeParams<'static, (), (), imp::IntoIter<()>>: imp::Immutable);
61 util_assert_impl_all!(TypeParams<'static, util::AU16, util::AU16, imp::IntoIter<()>>: imp::Immutable);
62 util_assert_impl_all!(TypeParams<'static, util::AU16, imp::UnsafeCell<u8>, imp::IntoIter<()>>: imp::Immutable);
63 util_assert_not_impl_any!(TypeParams<'static, imp::UnsafeCell<()>, (), imp::IntoIter<()>>: imp::Immutable);
64 util_assert_not_impl_any!(TypeParams<'static, [imp::UnsafeCell<u8>; 0], (), imp::IntoIter<()>>: imp::Immutable);
65 util_assert_not_impl_any!(TypeParams<'static, (), (), imp::IntoIter<imp::UnsafeCell<()>>>: imp::Immutable);
66
67 trait Trait {
68 type Assoc;
69 }
70
71 impl<T> Trait for imp::UnsafeCell<T> {
72 type Assoc = T;
73 }
74
75 #[derive(imp::Immutable)]
76 struct WithAssocType<T: Trait> {
77 field: <T as Trait>::Assoc,
78 }
79
80 util_assert_impl_all!(WithAssocType<imp::UnsafeCell<u8>>: imp::Immutable);
81
82 // Deriving `Immutable` should work if the struct has bounded parameters.
83
84 #[derive(imp::Immutable)]
85 #[repr(C)]
86 struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::Immutable, const N: usize>(
87 [T; N],
88 imp::PhantomData<&'a &'b ()>,
89 imp::PhantomData<imp::UnsafeCell<()>>,
90 &'a imp::UnsafeCell<()>,
91 )
92 where
93 'a: 'b,
94 'b: 'a,
95 T: 'a + 'b + imp::Immutable;
96
97 util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::Immutable);