Skip to content

Commit 7f7c5af

Browse files
committed
Move unsigned MIN and MAX into signedness_dependent_methods
1 parent 4419136 commit 7f7c5af

File tree

1 file changed

+26
-43
lines changed

1 file changed

+26
-43
lines changed

library/core/src/num/nonzero.rs

+26-43
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,37 @@ macro_rules! nonzero_integer_signedness_dependent_impls {
515515

516516
#[rustfmt::skip] // https://github.com/rust-lang/rustfmt/issues/5974
517517
macro_rules! nonzero_integer_signedness_dependent_methods {
518-
// Methods for unsigned nonzero types only.
518+
// Associated items for unsigned nonzero types only.
519519
(
520520
Self = $Ty:ident,
521521
Primitive = unsigned $Int:ident,
522522
UnsignedPrimitive = $Uint:ty,
523523
) => {
524+
/// The smallest value that can be represented by this non-zero
525+
/// integer type, 1.
526+
///
527+
/// # Examples
528+
///
529+
/// ```
530+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
531+
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN.get(), 1", stringify!($Int), ");")]
532+
/// ```
533+
#[stable(feature = "nonzero_min_max", since = "1.70.0")]
534+
pub const MIN: Self = Self::new(1).unwrap();
535+
536+
/// The largest value that can be represented by this non-zero
537+
/// integer type,
538+
#[doc = concat!("equal to [`", stringify!($Int), "::MAX`].")]
539+
///
540+
/// # Examples
541+
///
542+
/// ```
543+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
544+
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX.get(), ", stringify!($Int), "::MAX);")]
545+
/// ```
546+
#[stable(feature = "nonzero_min_max", since = "1.70.0")]
547+
pub const MAX: Self = Self::new(<$Int>::MAX).unwrap();
548+
524549
/// Adds an unsigned integer to a non-zero value.
525550
/// Checks for overflow and returns [`None`] on overflow.
526551
/// As a consequence, the result cannot wrap to zero.
@@ -1177,39 +1202,6 @@ macro_rules! sign_dependent_expr {
11771202
};
11781203
}
11791204

1180-
macro_rules! nonzero_min_max_unsigned {
1181-
( $( $Ty: ident($Int: ident); )+ ) => {
1182-
$(
1183-
impl $Ty {
1184-
/// The smallest value that can be represented by this non-zero
1185-
/// integer type, 1.
1186-
///
1187-
/// # Examples
1188-
///
1189-
/// ```
1190-
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
1191-
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN.get(), 1", stringify!($Int), ");")]
1192-
/// ```
1193-
#[stable(feature = "nonzero_min_max", since = "1.70.0")]
1194-
pub const MIN: Self = Self::new(1).unwrap();
1195-
1196-
/// The largest value that can be represented by this non-zero
1197-
/// integer type,
1198-
#[doc = concat!("equal to [`", stringify!($Int), "::MAX`].")]
1199-
///
1200-
/// # Examples
1201-
///
1202-
/// ```
1203-
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
1204-
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX.get(), ", stringify!($Int), "::MAX);")]
1205-
/// ```
1206-
#[stable(feature = "nonzero_min_max", since = "1.70.0")]
1207-
pub const MAX: Self = Self::new(<$Int>::MAX).unwrap();
1208-
}
1209-
)+
1210-
}
1211-
}
1212-
12131205
macro_rules! nonzero_min_max_signed {
12141206
( $( $Ty: ident($Int: ident); )+ ) => {
12151207
$(
@@ -1252,15 +1244,6 @@ macro_rules! nonzero_min_max_signed {
12521244
}
12531245
}
12541246

1255-
nonzero_min_max_unsigned! {
1256-
NonZeroU8(u8);
1257-
NonZeroU16(u16);
1258-
NonZeroU32(u32);
1259-
NonZeroU64(u64);
1260-
NonZeroU128(u128);
1261-
NonZeroUsize(usize);
1262-
}
1263-
12641247
nonzero_min_max_signed! {
12651248
NonZeroI8(i8);
12661249
NonZeroI16(i16);

0 commit comments

Comments
 (0)