Skip to content

Commit 54cb822

Browse files
committed
Define only a single NonZero type per macro call
Later in this stack, as the nonzero_integers macro is going to be responsible for producing a larger fraction of the API for the NonZero integer types, it will need to receive a number of additional arguments beyond the ones currently seen here. Additional arguments, especially named arguments across multiple lines, will turn out clearer if everything in one macro call is for the same NonZero type. This commit adopts a similar arrangement to what we do for generating the API of the integer primitives (`impl u8` etc), which also generate a single type's API per top-level macro call, rather than generating all 12 impl blocks for the 12 types from one macro call.
1 parent 56df3bb commit 54cb822

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

library/core/src/num/nonzero.rs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ macro_rules! impl_nonzero_fmt {
2222
}
2323
}
2424

25-
macro_rules! nonzero_integers {
26-
( $( #[$stability: meta] #[$const_new_unchecked_stability: meta] $Ty: ident($Int: ty); )+ ) => {
27-
$(
25+
macro_rules! nonzero_integer {
26+
(
27+
#[$stability:meta] #[$const_new_unchecked_stability:meta] $Ty:ident($Int:ty);
28+
) => {
2829
/// An integer that is known not to equal zero.
2930
///
3031
/// This enables some memory layout optimization.
@@ -186,8 +187,7 @@ macro_rules! nonzero_integers {
186187
impl_nonzero_fmt! {
187188
#[$stability] (Debug, Display, Binary, Octal, LowerHex, UpperHex) for $Ty
188189
}
189-
)+
190-
}
190+
};
191191
}
192192

193193
macro_rules! from_str_radix_nzint_impl {
@@ -1382,17 +1382,50 @@ nonzero_bits! {
13821382
NonZeroIsize(isize);
13831383
}
13841384

1385-
nonzero_integers! {
1385+
nonzero_integer! {
13861386
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
1387+
}
1388+
1389+
nonzero_integer! {
13871390
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
1391+
}
1392+
1393+
nonzero_integer! {
13881394
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
1395+
}
1396+
1397+
nonzero_integer! {
13891398
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU64(u64);
1399+
}
1400+
1401+
nonzero_integer! {
13901402
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU128(u128);
1403+
}
1404+
1405+
nonzero_integer! {
13911406
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroUsize(usize);
1407+
}
1408+
1409+
nonzero_integer! {
13921410
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI8(i8);
1411+
}
1412+
1413+
nonzero_integer! {
13931414
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI16(i16);
1415+
}
1416+
1417+
nonzero_integer! {
13941418
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI32(i32);
1419+
}
1420+
1421+
nonzero_integer! {
13951422
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI64(i64);
1423+
}
1424+
1425+
nonzero_integer! {
13961426
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI128(i128);
1427+
}
1428+
1429+
nonzero_integer! {
13971430
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroIsize(isize);
13981431
}

0 commit comments

Comments
 (0)