Skip to content

Commit 0f66ffc

Browse files
committed
Move BITS into omnibus impl block
1 parent 34a73f1 commit 0f66ffc

File tree

1 file changed

+14
-37
lines changed

1 file changed

+14
-37
lines changed

library/core/src/num/nonzero.rs

+14-37
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ macro_rules! nonzero_integer {
116116
self.0
117117
}
118118

119+
/// The size of this non-zero integer type in bits.
120+
///
121+
#[doc = concat!("This value is equal to [`", stringify!($Int), "::BITS`].")]
122+
///
123+
/// # Examples
124+
///
125+
/// ```
126+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
127+
///
128+
#[doc = concat!("assert_eq!(", stringify!($Ty), "::BITS, ", stringify!($Int), "::BITS);")]
129+
/// ```
130+
#[stable(feature = "nonzero_bits", since = "1.67.0")]
131+
pub const BITS: u32 = <$Int>::BITS;
132+
119133
/// Returns the number of leading zeros in the binary representation of `self`.
120134
///
121135
/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
@@ -1222,43 +1236,6 @@ macro_rules! sign_dependent_expr {
12221236
};
12231237
}
12241238

1225-
macro_rules! nonzero_bits {
1226-
( $( $Ty: ident($Int: ty); )+ ) => {
1227-
$(
1228-
impl $Ty {
1229-
/// The size of this non-zero integer type in bits.
1230-
///
1231-
#[doc = concat!("This value is equal to [`", stringify!($Int), "::BITS`].")]
1232-
///
1233-
/// # Examples
1234-
///
1235-
/// ```
1236-
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
1237-
///
1238-
#[doc = concat!("assert_eq!(", stringify!($Ty), "::BITS, ", stringify!($Int), "::BITS);")]
1239-
/// ```
1240-
#[stable(feature = "nonzero_bits", since = "1.67.0")]
1241-
pub const BITS: u32 = <$Int>::BITS;
1242-
}
1243-
)+
1244-
}
1245-
}
1246-
1247-
nonzero_bits! {
1248-
NonZeroU8(u8);
1249-
NonZeroI8(i8);
1250-
NonZeroU16(u16);
1251-
NonZeroI16(i16);
1252-
NonZeroU32(u32);
1253-
NonZeroI32(i32);
1254-
NonZeroU64(u64);
1255-
NonZeroI64(i64);
1256-
NonZeroU128(u128);
1257-
NonZeroI128(i128);
1258-
NonZeroUsize(usize);
1259-
NonZeroIsize(isize);
1260-
}
1261-
12621239
nonzero_integer! {
12631240
Self = NonZeroU8,
12641241
Primitive = unsigned u8,

0 commit comments

Comments
 (0)