1use super::*;
2
3pub unsafe trait Zeroable: Sized {
26 #[inline]
32 fn zeroed() -> Self {
33 unsafe { core::mem::zeroed() }
34 }
35}
36unsafe impl Zeroable for () {}
37unsafe impl Zeroable for bool {}
38unsafe impl Zeroable for char {}
39unsafe impl Zeroable for u8 {}
40unsafe impl Zeroable for i8 {}
41unsafe impl Zeroable for u16 {}
42unsafe impl Zeroable for i16 {}
43unsafe impl Zeroable for u32 {}
44unsafe impl Zeroable for i32 {}
45unsafe impl Zeroable for u64 {}
46unsafe impl Zeroable for i64 {}
47unsafe impl Zeroable for usize {}
48unsafe impl Zeroable for isize {}
49unsafe impl Zeroable for u128 {}
50unsafe impl Zeroable for i128 {}
51#[cfg(feature = "nightly_float")]
52unsafe impl Zeroable for f16 {}
53unsafe impl Zeroable for f32 {}
54unsafe impl Zeroable for f64 {}
55#[cfg(feature = "nightly_float")]
56unsafe impl Zeroable for f128 {}
57unsafe impl<T: Zeroable> Zeroable for Wrapping<T> {}
58unsafe impl<T: Zeroable> Zeroable for core::cmp::Reverse<T> {}
59#[cfg(feature = "pod_saturating")]
60unsafe impl<T: Zeroable> Zeroable for core::num::Saturating<T> {}
61
62unsafe impl<T> Zeroable for *mut T {}
67unsafe impl<T> Zeroable for *const T {}
68unsafe impl<T> Zeroable for *mut [T] {}
69unsafe impl<T> Zeroable for *const [T] {}
70unsafe impl Zeroable for *mut str {}
71unsafe impl Zeroable for *const str {}
72
73unsafe impl<T: ?Sized> Zeroable for PhantomData<T> {}
74unsafe impl Zeroable for PhantomPinned {}
75unsafe impl<T: Zeroable> Zeroable for core::mem::ManuallyDrop<T> {}
76unsafe impl<T: Zeroable> Zeroable for core::cell::UnsafeCell<T> {}
77unsafe impl<T: Zeroable> Zeroable for core::cell::Cell<T> {}
78
79#[cfg(feature = "zeroable_atomics")]
80#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "zeroable_atomics")))]
81mod atomic_impls {
82 use super::Zeroable;
83
84 #[cfg(target_has_atomic = "8")]
85 unsafe impl Zeroable for core::sync::atomic::AtomicBool {}
86 #[cfg(target_has_atomic = "8")]
87 unsafe impl Zeroable for core::sync::atomic::AtomicU8 {}
88 #[cfg(target_has_atomic = "8")]
89 unsafe impl Zeroable for core::sync::atomic::AtomicI8 {}
90
91 #[cfg(target_has_atomic = "16")]
92 unsafe impl Zeroable for core::sync::atomic::AtomicU16 {}
93 #[cfg(target_has_atomic = "16")]
94 unsafe impl Zeroable for core::sync::atomic::AtomicI16 {}
95
96 #[cfg(target_has_atomic = "32")]
97 unsafe impl Zeroable for core::sync::atomic::AtomicU32 {}
98 #[cfg(target_has_atomic = "32")]
99 unsafe impl Zeroable for core::sync::atomic::AtomicI32 {}
100
101 #[cfg(target_has_atomic = "64")]
102 unsafe impl Zeroable for core::sync::atomic::AtomicU64 {}
103 #[cfg(target_has_atomic = "64")]
104 unsafe impl Zeroable for core::sync::atomic::AtomicI64 {}
105
106 #[cfg(target_has_atomic = "ptr")]
107 unsafe impl Zeroable for core::sync::atomic::AtomicUsize {}
108 #[cfg(target_has_atomic = "ptr")]
109 unsafe impl Zeroable for core::sync::atomic::AtomicIsize {}
110
111 #[cfg(target_has_atomic = "ptr")]
112 unsafe impl<T> Zeroable for core::sync::atomic::AtomicPtr<T> {}
113}
114
115#[cfg(feature = "zeroable_maybe_uninit")]
116#[cfg_attr(
117 feature = "nightly_docs",
118 doc(cfg(feature = "zeroable_maybe_uninit"))
119)]
120unsafe impl<T> Zeroable for core::mem::MaybeUninit<T> {}
121
122unsafe impl<A: Zeroable> Zeroable for (A,) {}
123unsafe impl<A: Zeroable, B: Zeroable> Zeroable for (A, B) {}
124unsafe impl<A: Zeroable, B: Zeroable, C: Zeroable> Zeroable for (A, B, C) {}
125unsafe impl<A: Zeroable, B: Zeroable, C: Zeroable, D: Zeroable> Zeroable
126 for (A, B, C, D)
127{
128}
129unsafe impl<A: Zeroable, B: Zeroable, C: Zeroable, D: Zeroable, E: Zeroable>
130 Zeroable for (A, B, C, D, E)
131{
132}
133unsafe impl<
134 A: Zeroable,
135 B: Zeroable,
136 C: Zeroable,
137 D: Zeroable,
138 E: Zeroable,
139 F: Zeroable,
140 > Zeroable for (A, B, C, D, E, F)
141{
142}
143unsafe impl<
144 A: Zeroable,
145 B: Zeroable,
146 C: Zeroable,
147 D: Zeroable,
148 E: Zeroable,
149 F: Zeroable,
150 G: Zeroable,
151 > Zeroable for (A, B, C, D, E, F, G)
152{
153}
154unsafe impl<
155 A: Zeroable,
156 B: Zeroable,
157 C: Zeroable,
158 D: Zeroable,
159 E: Zeroable,
160 F: Zeroable,
161 G: Zeroable,
162 H: Zeroable,
163 > Zeroable for (A, B, C, D, E, F, G, H)
164{
165}
166
167#[cfg(feature = "min_const_generics")]
168#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "min_const_generics")))]
169unsafe impl<T, const N: usize> Zeroable for [T; N] where T: Zeroable {}
170
171#[cfg(not(feature = "min_const_generics"))]
172impl_unsafe_marker_for_array!(
173 Zeroable, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
174 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 48, 64, 96, 128, 256,
175 512, 1024, 2048, 4096
176);
177
178impl_unsafe_marker_for_simd!(
179 #[cfg(all(target_arch = "wasm32", feature = "wasm_simd"))]
180 unsafe impl Zeroable for wasm32::{v128}
181);
182
183impl_unsafe_marker_for_simd!(
184 #[cfg(all(target_arch = "aarch64", feature = "aarch64_simd"))]
185 unsafe impl Zeroable for aarch64::{
186 float32x2_t, float32x2x2_t, float32x2x3_t, float32x2x4_t, float32x4_t,
187 float32x4x2_t, float32x4x3_t, float32x4x4_t, float64x1_t, float64x1x2_t,
188 float64x1x3_t, float64x1x4_t, float64x2_t, float64x2x2_t, float64x2x3_t,
189 float64x2x4_t, int16x4_t, int16x4x2_t, int16x4x3_t, int16x4x4_t, int16x8_t,
190 int16x8x2_t, int16x8x3_t, int16x8x4_t, int32x2_t, int32x2x2_t, int32x2x3_t,
191 int32x2x4_t, int32x4_t, int32x4x2_t, int32x4x3_t, int32x4x4_t, int64x1_t,
192 int64x1x2_t, int64x1x3_t, int64x1x4_t, int64x2_t, int64x2x2_t, int64x2x3_t,
193 int64x2x4_t, int8x16_t, int8x16x2_t, int8x16x3_t, int8x16x4_t, int8x8_t,
194 int8x8x2_t, int8x8x3_t, int8x8x4_t, poly16x4_t, poly16x4x2_t, poly16x4x3_t,
195 poly16x4x4_t, poly16x8_t, poly16x8x2_t, poly16x8x3_t, poly16x8x4_t,
196 poly64x1_t, poly64x1x2_t, poly64x1x3_t, poly64x1x4_t, poly64x2_t,
197 poly64x2x2_t, poly64x2x3_t, poly64x2x4_t, poly8x16_t, poly8x16x2_t,
198 poly8x16x3_t, poly8x16x4_t, poly8x8_t, poly8x8x2_t, poly8x8x3_t, poly8x8x4_t,
199 uint16x4_t, uint16x4x2_t, uint16x4x3_t, uint16x4x4_t, uint16x8_t,
200 uint16x8x2_t, uint16x8x3_t, uint16x8x4_t, uint32x2_t, uint32x2x2_t,
201 uint32x2x3_t, uint32x2x4_t, uint32x4_t, uint32x4x2_t, uint32x4x3_t,
202 uint32x4x4_t, uint64x1_t, uint64x1x2_t, uint64x1x3_t, uint64x1x4_t,
203 uint64x2_t, uint64x2x2_t, uint64x2x3_t, uint64x2x4_t, uint8x16_t,
204 uint8x16x2_t, uint8x16x3_t, uint8x16x4_t, uint8x8_t, uint8x8x2_t,
205 uint8x8x3_t, uint8x8x4_t,
206 }
207);
208
209impl_unsafe_marker_for_simd!(
210 #[cfg(target_arch = "x86")]
211 unsafe impl Zeroable for x86::{
212 __m128i, __m128, __m128d,
213 __m256i, __m256, __m256d,
214 }
215);
216
217impl_unsafe_marker_for_simd!(
218 #[cfg(target_arch = "x86_64")]
219 unsafe impl Zeroable for x86_64::{
220 __m128i, __m128, __m128d,
221 __m256i, __m256, __m256d,
222 }
223);
224
225#[rustversion::before(2026-01-27)] #[cfg(feature = "nightly_portable_simd")]
227#[cfg_attr(
228 feature = "nightly_docs",
229 doc(cfg(feature = "nightly_portable_simd"))
230)]
231unsafe impl<T, const N: usize> Zeroable for core::simd::Simd<T, N>
232where
233 T: core::simd::SimdElement + Zeroable,
234 core::simd::LaneCount<N>: core::simd::SupportedLaneCount,
235{
236}
237
238#[rustversion::since(2026-01-27)] #[cfg(feature = "nightly_portable_simd")]
240#[cfg_attr(
241 feature = "nightly_docs",
242 doc(cfg(feature = "nightly_portable_simd"))
243)]
244unsafe impl<T, const N: usize> Zeroable for core::simd::Simd<T, N>
245where
246 T: core::simd::SimdElement + Zeroable,
247{
248}
249
250impl_unsafe_marker_for_simd!(
251 #[cfg(all(target_arch = "x86", feature = "avx512_simd"))]
252 unsafe impl Zeroable for x86::{
253 __m512, __m512d, __m512i
254 }
255);
256
257impl_unsafe_marker_for_simd!(
258 #[cfg(all(target_arch = "x86_64", feature = "avx512_simd"))]
259 unsafe impl Zeroable for x86_64::{
260 __m512, __m512d, __m512i
261 }
262);
263
264impl_unsafe_marker_for_simd!(
265 #[cfg(all(target_arch = "x86", feature = "avx512_simd"))]
266 unsafe impl Zeroable for x86::{
267 __m128bh, __m256bh, __m512bh
268 }
269);
270
271impl_unsafe_marker_for_simd!(
272 #[cfg(all(target_arch = "x86_64", feature = "avx512_simd"))]
273 unsafe impl Zeroable for x86_64::{
274 __m128bh, __m256bh, __m512bh
275 }
276);