Skip to content

Commit c537132

Browse files
committed
Move BITS into omnibus impl block
1 parent 66cda3b commit c537132

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
@@ -128,6 +128,20 @@ macro_rules! nonzero_integer {
128128
self.0
129129
}
130130

131+
/// The size of this non-zero integer type in bits.
132+
///
133+
#[doc = concat!("This value is equal to [`", stringify!($Int), "::BITS`].")]
134+
///
135+
/// # Examples
136+
///
137+
/// ```
138+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
139+
///
140+
#[doc = concat!("assert_eq!(", stringify!($Ty), "::BITS, ", stringify!($Int), "::BITS);")]
141+
/// ```
142+
#[stable(feature = "nonzero_bits", since = "1.67.0")]
143+
pub const BITS: u32 = <$Int>::BITS;
144+
131145
/// Returns the number of leading zeros in the binary representation of `self`.
132146
///
133147
/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
@@ -1236,43 +1250,6 @@ macro_rules! sign_dependent_expr {
12361250
};
12371251
}
12381252

1239-
macro_rules! nonzero_bits {
1240-
( $( $Ty: ident($Int: ty); )+ ) => {
1241-
$(
1242-
impl $Ty {
1243-
/// The size of this non-zero integer type in bits.
1244-
///
1245-
#[doc = concat!("This value is equal to [`", stringify!($Int), "::BITS`].")]
1246-
///
1247-
/// # Examples
1248-
///
1249-
/// ```
1250-
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
1251-
///
1252-
#[doc = concat!("assert_eq!(", stringify!($Ty), "::BITS, ", stringify!($Int), "::BITS);")]
1253-
/// ```
1254-
#[stable(feature = "nonzero_bits", since = "1.67.0")]
1255-
pub const BITS: u32 = <$Int>::BITS;
1256-
}
1257-
)+
1258-
}
1259-
}
1260-
1261-
nonzero_bits! {
1262-
NonZeroU8(u8);
1263-
NonZeroI8(i8);
1264-
NonZeroU16(u16);
1265-
NonZeroI16(i16);
1266-
NonZeroU32(u32);
1267-
NonZeroI32(i32);
1268-
NonZeroU64(u64);
1269-
NonZeroI64(i64);
1270-
NonZeroU128(u128);
1271-
NonZeroI128(i128);
1272-
NonZeroUsize(usize);
1273-
NonZeroIsize(isize);
1274-
}
1275-
12761253
nonzero_integer! {
12771254
Self = NonZeroU8,
12781255
Primitive = unsigned u8,

0 commit comments

Comments
 (0)