about summary refs log tree commit diff
path: root/library/alloc/src/vec
diff options
context:
space:
mode:
authorclubby789 <jamie@hill-daniel.co.uk>2023-01-17 15:42:53 +0000
committerclubby789 <jamie@hill-daniel.co.uk>2023-01-18 15:15:15 +0000
commitb94a29a25ff9ca4a8edfc0b6c7d1d309dc03d5cd (patch)
tree6a52e6646a627f215034989abf845ea35157a12c /library/alloc/src/vec
parentf34cc658eb477958e2b73e05586e7af66faefad9 (diff)
downloadrust-b94a29a25ff9ca4a8edfc0b6c7d1d309dc03d5cd.tar.gz
rust-b94a29a25ff9ca4a8edfc0b6c7d1d309dc03d5cd.zip
Implement `alloc::vec::IsZero` for `Option<$NUM>` types
Diffstat (limited to 'library/alloc/src/vec')
-rw-r--r--library/alloc/src/vec/is_zero.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/library/alloc/src/vec/is_zero.rs b/library/alloc/src/vec/is_zero.rs
index 26120270c0c..2b6be14de79 100644
--- a/library/alloc/src/vec/is_zero.rs
+++ b/library/alloc/src/vec/is_zero.rs
@@ -147,6 +147,23 @@ impl_is_zero_option_of_nonzero!(
     NonZeroIsize,
 );
 
+macro_rules! impl_is_zero_option_of_num {
+    ($($t:ty,)+) => {$(
+        unsafe impl IsZero for Option<$t> {
+            #[inline]
+            fn is_zero(&self) -> bool {
+                const {
+                    let none: Self = unsafe { core::mem::MaybeUninit::zeroed().assume_init() };
+                    assert!(none.is_none());
+                }
+                self.is_none()
+            }
+        }
+    )+};
+}
+
+impl_is_zero_option_of_num!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, usize, isize,);
+
 unsafe impl<T: IsZero> IsZero for Wrapping<T> {
     #[inline]
     fn is_zero(&self) -> bool {