Skip to content

Commit 9f711ab

Browse files
committed
Move unsigned MIN and MAX into signedness_dependent_methods
1 parent 0ae539f commit 9f711ab

File tree

1 file changed

+26
-43
lines changed

1 file changed

+26
-43
lines changed

library/core/src/num/nonzero.rs

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,37 @@ macro_rules! nonzero_integer_signedness_dependent_impls {
501501

502502
#[rustfmt::skip] // https://github.com/rust-lang/rustfmt/issues/5974
503503
macro_rules! nonzero_integer_signedness_dependent_methods {
504-
// Methods for unsigned nonzero types only.
504+
// Associated items for unsigned nonzero types only.
505505
(
506506
Self = $Ty:ident,
507507
Primitive = unsigned $Int:ident,
508508
UnsignedPrimitive = $Uint:ty,
509509
) => {
510+
/// The smallest value that can be represented by this non-zero
511+
/// integer type, 1.
512+
///
513+
/// # Examples
514+
///
515+
/// ```
516+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
517+
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN.get(), 1", stringify!($Int), ");")]
518+
/// ```
519+
#[stable(feature = "nonzero_min_max", since = "1.70.0")]
520+
pub const MIN: Self = Self::new(1).unwrap();
521+
522+
/// The largest value that can be represented by this non-zero
523+
/// integer type,
524+
#[doc = concat!("equal to [`", stringify!($Int), "::MAX`].")]
525+
///
526+
/// # Examples
527+
///
528+
/// ```
529+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
530+
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX.get(), ", stringify!($Int), "::MAX);")]
531+
/// ```
532+
#[stable(feature = "nonzero_min_max", since = "1.70.0")]
533+
pub const MAX: Self = Self::new(<$Int>::MAX).unwrap();
534+
510535
/// Adds an unsigned integer to a non-zero value.
511536
/// Checks for overflow and returns [`None`] on overflow.
512537
/// As a consequence, the result cannot wrap to zero.
@@ -1163,39 +1188,6 @@ macro_rules! sign_dependent_expr {
11631188
};
11641189
}
11651190

1166-
macro_rules! nonzero_min_max_unsigned {
1167-
( $( $Ty: ident($Int: ident); )+ ) => {
1168-
$(
1169-
impl $Ty {
1170-
/// The smallest value that can be represented by this non-zero
1171-
/// integer type, 1.
1172-
///
1173-
/// # Examples
1174-
///
1175-
/// ```
1176-
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
1177-
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN.get(), 1", stringify!($Int), ");")]
1178-
/// ```
1179-
#[stable(feature = "nonzero_min_max", since = "1.70.0")]
1180-
pub const MIN: Self = Self::new(1).unwrap();
1181-
1182-
/// The largest value that can be represented by this non-zero
1183-
/// integer type,
1184-
#[doc = concat!("equal to [`", stringify!($Int), "::MAX`].")]
1185-
///
1186-
/// # Examples
1187-
///
1188-
/// ```
1189-
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
1190-
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX.get(), ", stringify!($Int), "::MAX);")]
1191-
/// ```
1192-
#[stable(feature = "nonzero_min_max", since = "1.70.0")]
1193-
pub const MAX: Self = Self::new(<$Int>::MAX).unwrap();
1194-
}
1195-
)+
1196-
}
1197-
}
1198-
11991191
macro_rules! nonzero_min_max_signed {
12001192
( $( $Ty: ident($Int: ident); )+ ) => {
12011193
$(
@@ -1238,15 +1230,6 @@ macro_rules! nonzero_min_max_signed {
12381230
}
12391231
}
12401232

1241-
nonzero_min_max_unsigned! {
1242-
NonZeroU8(u8);
1243-
NonZeroU16(u16);
1244-
NonZeroU32(u32);
1245-
NonZeroU64(u64);
1246-
NonZeroU128(u128);
1247-
NonZeroUsize(usize);
1248-
}
1249-
12501233
nonzero_min_max_signed! {
12511234
NonZeroI8(i8);
12521235
NonZeroI16(i16);

0 commit comments

Comments
 (0)