Skip to content

Commit b3ad54b

Browse files
committed
Implement alloc::vec::IsZero for Option<$NUM> types
1 parent bde4ba1 commit b3ad54b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
#![feature(const_size_of_val)]
107107
#![feature(const_align_of_val)]
108108
#![feature(const_ptr_read)]
109+
#![feature(const_maybe_uninit_zeroed)]
109110
#![feature(const_maybe_uninit_write)]
110111
#![feature(const_maybe_uninit_as_mut_ptr)]
111112
#![feature(const_refs_to_cell)]

alloc/src/vec/is_zero.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,23 @@ impl_is_zero_option_of_nonzero!(
147147
NonZeroIsize,
148148
);
149149

150+
macro_rules! impl_is_zero_option_of_num {
151+
($($t:ty,)+) => {$(
152+
unsafe impl IsZero for Option<$t> {
153+
#[inline]
154+
fn is_zero(&self) -> bool {
155+
const {
156+
let none: Self = unsafe { core::mem::MaybeUninit::zeroed().assume_init() };
157+
assert!(none.is_none());
158+
}
159+
self.is_none()
160+
}
161+
}
162+
)+};
163+
}
164+
165+
impl_is_zero_option_of_num!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, usize, isize,);
166+
150167
unsafe impl<T: IsZero> IsZero for Wrapping<T> {
151168
#[inline]
152169
fn is_zero(&self) -> bool {

0 commit comments

Comments
 (0)