Debian Codegraph @

debian/rust-vendor/zerocopy-derive/tests/deprecated.rs

raw
1 // Copyright 2024 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 #![deny(deprecated)]
13
14 include!("include.rs");
15
16 // Make sure no deprecation warnings are generated from our derives (see #553).
17
18 #[macro_export]
19 macro_rules! test {
20 ($name:ident => $ty:item => $($trait:ident),*) => {
21 #[allow(non_snake_case)]
22 mod $name {
23 $(
24 mod $trait {
25 use super::super::*;
26
27 #[deprecated = "do not use"]
28 #[derive(imp::$trait)]
29 #[zerocopy(crate = "zerocopy_renamed")]
30 $ty
31
32 #[allow(deprecated)]
33 fn _allow_deprecated() {
34 util_assert_impl_all!($name: imp::$trait);
35 }
36 }
37 )*
38 }
39 };
40 }
41
42 // NOTE: `FromBytes` is tested separately in `enum_from_bytes.rs` since it
43 // requires 256-variant enums which are extremely verbose; such enums are
44 // already in that file.
45 test!(Enum => #[repr(u8)] enum Enum { A, } => TryFromBytes, FromZeros, KnownLayout, Immutable, IntoBytes, Unaligned);
46
47 test!(Struct => #[repr(C)] struct Struct; => TryFromBytes, FromZeros, FromBytes, KnownLayout, Immutable, IntoBytes, Unaligned);
48
49 test!(Union => #[repr(C)] union Union{ a: (), } => TryFromBytes, FromZeros, FromBytes, KnownLayout, Immutable, IntoBytes, Unaligned);
50
51 // Tests for ByteHash and ByteEq which require IntoBytes + Immutable
52 mod enum_hash_eq {
53 mod ByteHash {
54 use super::super::*;
55 #[deprecated = "do not use"]
56 #[derive(imp::ByteHash, imp::IntoBytes, imp::Immutable)]
57 #[zerocopy(crate = "zerocopy_renamed")]
58 #[repr(u8)]
59 enum Enum {
60 A,
61 }
62
63 #[allow(deprecated)]
64 fn _allow_deprecated() {
65 util_assert_impl_all!(Enum: ::core::hash::Hash);
66 }
67 }
68 mod ByteEq {
69 use super::super::*;
70 #[deprecated = "do not use"]
71 #[derive(imp::ByteEq, imp::IntoBytes, imp::Immutable)]
72 #[zerocopy(crate = "zerocopy_renamed")]
73 #[repr(u8)]
74 enum Enum {
75 A,
76 }
77
78 #[allow(deprecated)]
79 fn _allow_deprecated() {
80 util_assert_impl_all!(Enum: ::core::cmp::PartialEq, ::core::cmp::Eq);
81 }
82 }
83 }
84
85 mod struct_hash_eq {
86 mod ByteHash {
87 use super::super::*;
88 #[deprecated = "do not use"]
89 #[derive(imp::ByteHash, imp::IntoBytes, imp::Immutable)]
90 #[zerocopy(crate = "zerocopy_renamed")]
91 #[repr(C)]
92 struct Struct;
93
94 #[allow(deprecated)]
95 fn _allow_deprecated() {
96 util_assert_impl_all!(Struct: ::core::hash::Hash);
97 }
98 }
99 mod ByteEq {
100 use super::super::*;
101 #[deprecated = "do not use"]
102 #[derive(imp::ByteEq, imp::IntoBytes, imp::Immutable)]
103 #[zerocopy(crate = "zerocopy_renamed")]
104 #[repr(C)]
105 struct Struct;
106
107 #[allow(deprecated)]
108 fn _allow_deprecated() {
109 util_assert_impl_all!(Struct: ::core::cmp::PartialEq, ::core::cmp::Eq);
110 }
111 }
112 }
113
114 // Tests for SplitAt which requires repr(C) and at least one field
115 mod split_at_test {
116 mod SplitAt {
117 use super::super::*;
118 #[deprecated = "do not use"]
119 #[derive(imp::SplitAt, imp::KnownLayout)]
120 #[zerocopy(crate = "zerocopy_renamed")]
121 #[repr(C)]
122 struct Struct {
123 a: [u8],
124 }
125
126 #[allow(deprecated)]
127 fn _allow_deprecated() {
128 util_assert_impl_all!(Struct: imp::SplitAt);
129 }
130 }
131 }