Skip to content

Commit a6152cd

Browse files
committed
Format nonzero_integer macro calls same way we do the primitive int impls
The `key = $value` style will be beneficial as we introduce some more macro arguments here in later commits.
1 parent 9196d2a commit a6152cd

File tree

1 file changed

+59
-20
lines changed

1 file changed

+59
-20
lines changed

library/core/src/num/nonzero.rs

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ macro_rules! impl_nonzero_fmt {
2424

2525
macro_rules! nonzero_integer {
2626
(
27-
#[$stability:meta] #[$const_new_unchecked_stability:meta] $Ty:ident($Int:ty);
27+
Self = $Ty:ident,
28+
Primitive = $signedness:ident $Int:ident,
29+
feature = $feature:literal,
30+
original_stabilization = $since:literal,
2831
) => {
2932
/// An integer that is known not to equal zero.
3033
///
@@ -56,7 +59,7 @@ macro_rules! nonzero_integer {
5659
/// ```
5760
///
5861
/// [null pointer optimization]: crate::option#representation
59-
#[$stability]
62+
#[stable(feature = $feature, since = $since)]
6063
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
6164
#[repr(transparent)]
6265
#[rustc_layout_scalar_valid_range_start(1)]
@@ -71,8 +74,8 @@ macro_rules! nonzero_integer {
7174
/// # Safety
7275
///
7376
/// The value must not be zero.
74-
#[$stability]
75-
#[$const_new_unchecked_stability]
77+
#[stable(feature = $feature, since = $since)]
78+
#[rustc_const_stable(feature = $feature, since = $since)]
7679
#[must_use]
7780
#[inline]
7881
pub const unsafe fn new_unchecked(n: $Int) -> Self {
@@ -87,7 +90,7 @@ macro_rules! nonzero_integer {
8790
}
8891

8992
/// Creates a non-zero if the given value is not zero.
90-
#[$stability]
93+
#[stable(feature = $feature, since = $since)]
9194
#[rustc_const_stable(feature = "const_nonzero_int_methods", since = "1.47.0")]
9295
#[must_use]
9396
#[inline]
@@ -101,7 +104,7 @@ macro_rules! nonzero_integer {
101104
}
102105

103106
/// Returns the value as a primitive type.
104-
#[$stability]
107+
#[stable(feature = $feature, since = $since)]
105108
#[inline]
106109
#[rustc_const_stable(feature = "const_nonzero_get", since = "1.34.0")]
107110
pub const fn get(self) -> $Int {
@@ -119,7 +122,6 @@ macro_rules! nonzero_integer {
119122
}
120123
self.0
121124
}
122-
123125
}
124126

125127
#[stable(feature = "from_nonzero", since = "1.31.0")]
@@ -185,7 +187,8 @@ macro_rules! nonzero_integer {
185187
}
186188

187189
impl_nonzero_fmt! {
188-
#[$stability] (Debug, Display, Binary, Octal, LowerHex, UpperHex) for $Ty
190+
#[stable(feature = $feature, since = $since)]
191+
(Debug, Display, Binary, Octal, LowerHex, UpperHex) for $Ty
189192
}
190193
};
191194
}
@@ -1383,49 +1386,85 @@ nonzero_bits! {
13831386
}
13841387

13851388
nonzero_integer! {
1386-
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
1389+
Self = NonZeroU8,
1390+
Primitive = unsigned u8,
1391+
feature = "nonzero",
1392+
original_stabilization = "1.28.0",
13871393
}
13881394

13891395
nonzero_integer! {
1390-
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
1396+
Self = NonZeroU16,
1397+
Primitive = unsigned u16,
1398+
feature = "nonzero",
1399+
original_stabilization = "1.28.0",
13911400
}
13921401

13931402
nonzero_integer! {
1394-
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
1403+
Self = NonZeroU32,
1404+
Primitive = unsigned u32,
1405+
feature = "nonzero",
1406+
original_stabilization = "1.28.0",
13951407
}
13961408

13971409
nonzero_integer! {
1398-
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU64(u64);
1410+
Self = NonZeroU64,
1411+
Primitive = unsigned u64,
1412+
feature = "nonzero",
1413+
original_stabilization = "1.28.0",
13991414
}
14001415

14011416
nonzero_integer! {
1402-
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU128(u128);
1417+
Self = NonZeroU128,
1418+
Primitive = unsigned u128,
1419+
feature = "nonzero",
1420+
original_stabilization = "1.28.0",
14031421
}
14041422

14051423
nonzero_integer! {
1406-
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroUsize(usize);
1424+
Self = NonZeroUsize,
1425+
Primitive = unsigned usize,
1426+
feature = "nonzero",
1427+
original_stabilization = "1.28.0",
14071428
}
14081429

14091430
nonzero_integer! {
1410-
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI8(i8);
1431+
Self = NonZeroI8,
1432+
Primitive = signed i8,
1433+
feature = "signed_nonzero",
1434+
original_stabilization = "1.34.0",
14111435
}
14121436

14131437
nonzero_integer! {
1414-
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI16(i16);
1438+
Self = NonZeroI16,
1439+
Primitive = signed i16,
1440+
feature = "signed_nonzero",
1441+
original_stabilization = "1.34.0",
14151442
}
14161443

14171444
nonzero_integer! {
1418-
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI32(i32);
1445+
Self = NonZeroI32,
1446+
Primitive = signed i32,
1447+
feature = "signed_nonzero",
1448+
original_stabilization = "1.34.0",
14191449
}
14201450

14211451
nonzero_integer! {
1422-
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI64(i64);
1452+
Self = NonZeroI64,
1453+
Primitive = signed i64,
1454+
feature = "signed_nonzero",
1455+
original_stabilization = "1.34.0",
14231456
}
14241457

14251458
nonzero_integer! {
1426-
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI128(i128);
1459+
Self = NonZeroI128,
1460+
Primitive = signed i128,
1461+
feature = "signed_nonzero",
1462+
original_stabilization = "1.34.0",
14271463
}
14281464

14291465
nonzero_integer! {
1430-
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroIsize(isize);
1466+
Self = NonZeroIsize,
1467+
Primitive = signed isize,
1468+
feature = "signed_nonzero",
1469+
original_stabilization = "1.34.0",
14311470
}

0 commit comments

Comments
 (0)