Debian Codegraph @

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

raw
1 // Copyright 2025 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 // Test to make sure that all of our derives are compatible with `UnsafeCell`s.
16 //
17 // We test both `FromBytes` and `FromZeros`, as the `FromBytes` implied derive
18 // of `TryFromBytes` emits a trivial `is_bit_valid` impl - we want to test the
19 // non-trivial impl, which deriving `FromZeros` accomplishes.
20
21 #[derive(imp::FromBytes, imp::IntoBytes, imp::KnownLayout, imp::Unaligned)]
22 #[repr(C)]
23 struct StructFromBytes(imp::UnsafeCell<u8>);
24
25 #[derive(imp::FromZeros, imp::IntoBytes, imp::KnownLayout, imp::Unaligned)]
26 #[repr(C)]
27 struct StructFromZeros(imp::UnsafeCell<bool>);
28
29 #[derive(imp::FromZeros, imp::IntoBytes, imp::KnownLayout, imp::Unaligned)]
30 #[repr(u8)]
31 enum EnumFromZeros {
32 A(imp::UnsafeCell<bool>),
33 }