about summary refs log tree commit diff
path: root/library/alloc/src/vec/is_zero.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/alloc/src/vec/is_zero.rs')
-rw-r--r--library/alloc/src/vec/is_zero.rs51
1 files changed, 19 insertions, 32 deletions
diff --git a/library/alloc/src/vec/is_zero.rs b/library/alloc/src/vec/is_zero.rs
index cb9adf05c25..bcc5bf4d65b 100644
--- a/library/alloc/src/vec/is_zero.rs
+++ b/library/alloc/src/vec/is_zero.rs
@@ -1,4 +1,4 @@
-use core::num::{Saturating, Wrapping};
+use core::num::{NonZero, Saturating, Wrapping};
 
 use crate::boxed::Box;
 
@@ -69,7 +69,7 @@ unsafe impl<T: IsZero, const N: usize> IsZero for [T; N] {
 }
 
 // This is recursive macro.
-macro_rules! impl_for_tuples {
+macro_rules! impl_is_zero_tuples {
     // Stopper
     () => {
         // No use for implementing for empty tuple because it is ZST.
@@ -88,11 +88,11 @@ macro_rules! impl_for_tuples {
             }
         }
 
-        impl_for_tuples!($($rest),*);
+        impl_is_zero_tuples!($($rest),*);
     }
 }
 
-impl_for_tuples!(A, B, C, D, E, F, G, H);
+impl_is_zero_tuples!(A, B, C, D, E, F, G, H);
 
 // `Option<&T>` and `Option<Box<T>>` are guaranteed to represent `None` as null.
 // For fat pointers, the bytes that would be the pointer metadata in the `Some`
@@ -115,16 +115,15 @@ unsafe impl<T: ?Sized> IsZero for Option<Box<T>> {
     }
 }
 
-// `Option<num::NonZeroU32>` and similar have a representation guarantee that
+// `Option<NonZero<u32>>` and similar have a representation guarantee that
 // they're the same size as the corresponding `u32` type, as well as a guarantee
-// that transmuting between `NonZeroU32` and `Option<num::NonZeroU32>` works.
+// that transmuting between `NonZero<u32>` and `Option<NonZero<u32>>` works.
 // While the documentation officially makes it UB to transmute from `None`,
 // we're the standard library so we can make extra inferences, and we know that
 // the only niche available to represent `None` is the one that's all zeros.
-
-macro_rules! impl_is_zero_option_of_nonzero {
-    ($($t:ident,)+) => {$(
-        unsafe impl IsZero for Option<core::num::$t> {
+macro_rules! impl_is_zero_option_of_nonzero_int {
+    ($($t:ty),+ $(,)?) => {$(
+        unsafe impl IsZero for Option<NonZero<$t>> {
             #[inline]
             fn is_zero(&self) -> bool {
                 self.is_none()
@@ -133,23 +132,10 @@ macro_rules! impl_is_zero_option_of_nonzero {
     )+};
 }
 
-impl_is_zero_option_of_nonzero!(
-    NonZeroU8,
-    NonZeroU16,
-    NonZeroU32,
-    NonZeroU64,
-    NonZeroU128,
-    NonZeroI8,
-    NonZeroI16,
-    NonZeroI32,
-    NonZeroI64,
-    NonZeroI128,
-    NonZeroUsize,
-    NonZeroIsize,
-);
-
-macro_rules! impl_is_zero_option_of_num {
-    ($($t:ty,)+) => {$(
+impl_is_zero_option_of_nonzero_int!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
+
+macro_rules! impl_is_zero_option_of_int {
+    ($($t:ty),+ $(,)?) => {$(
         unsafe impl IsZero for Option<$t> {
             #[inline]
             fn is_zero(&self) -> bool {
@@ -163,7 +149,7 @@ macro_rules! impl_is_zero_option_of_num {
     )+};
 }
 
-impl_is_zero_option_of_num!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, usize, isize,);
+impl_is_zero_option_of_int!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, usize, isize);
 
 unsafe impl<T: IsZero> IsZero for Wrapping<T> {
     #[inline]
@@ -179,8 +165,8 @@ unsafe impl<T: IsZero> IsZero for Saturating<T> {
     }
 }
 
-macro_rules! impl_for_optional_bool {
-    ($($t:ty,)+) => {$(
+macro_rules! impl_is_zero_option_of_bool {
+    ($($t:ty),+ $(,)?) => {$(
         unsafe impl IsZero for $t {
             #[inline]
             fn is_zero(&self) -> bool {
@@ -194,9 +180,10 @@ macro_rules! impl_for_optional_bool {
         }
     )+};
 }
-impl_for_optional_bool! {
+
+impl_is_zero_option_of_bool! {
     Option<bool>,
     Option<Option<bool>>,
     Option<Option<Option<bool>>>,
-    // Could go further, but not worth the metadata overhead
+    // Could go further, but not worth the metadata overhead.
 }