Skip to content

Commit 34a73f1

Browse files
committed
Move signed MIN and MAX into signedness_dependent_methods
1 parent 9f711ab commit 34a73f1

File tree

1 file changed

+35
-52
lines changed

1 file changed

+35
-52
lines changed

library/core/src/num/nonzero.rs

+35-52
Original file line numberDiff line numberDiff line change
@@ -791,13 +791,47 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
791791
}
792792
};
793793

794-
// Methods for signed nonzero types only.
794+
// Associated items for signed nonzero types only.
795795
(
796796
Self = $Ty:ident,
797797
Primitive = signed $Int:ident,
798798
UnsignedNonZero = $Uty:ident,
799799
UnsignedPrimitive = $Uint:ty,
800800
) => {
801+
/// The smallest value that can be represented by this non-zero
802+
/// integer type,
803+
#[doc = concat!("equal to [`", stringify!($Int), "::MIN`].")]
804+
///
805+
/// Note: While most integer types are defined for every whole
806+
/// number between `MIN` and `MAX`, signed non-zero integers are
807+
/// a special case. They have a "gap" at 0.
808+
///
809+
/// # Examples
810+
///
811+
/// ```
812+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
813+
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN.get(), ", stringify!($Int), "::MIN);")]
814+
/// ```
815+
#[stable(feature = "nonzero_min_max", since = "1.70.0")]
816+
pub const MIN: Self = Self::new(<$Int>::MIN).unwrap();
817+
818+
/// The largest value that can be represented by this non-zero
819+
/// integer type,
820+
#[doc = concat!("equal to [`", stringify!($Int), "::MAX`].")]
821+
///
822+
/// Note: While most integer types are defined for every whole
823+
/// number between `MIN` and `MAX`, signed non-zero integers are
824+
/// a special case. They have a "gap" at 0.
825+
///
826+
/// # Examples
827+
///
828+
/// ```
829+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
830+
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX.get(), ", stringify!($Int), "::MAX);")]
831+
/// ```
832+
#[stable(feature = "nonzero_min_max", since = "1.70.0")]
833+
pub const MAX: Self = Self::new(<$Int>::MAX).unwrap();
834+
801835
/// Computes the absolute value of self.
802836
#[doc = concat!("See [`", stringify!($Int), "::abs`]")]
803837
/// for documentation on overflow behaviour.
@@ -1188,57 +1222,6 @@ macro_rules! sign_dependent_expr {
11881222
};
11891223
}
11901224

1191-
macro_rules! nonzero_min_max_signed {
1192-
( $( $Ty: ident($Int: ident); )+ ) => {
1193-
$(
1194-
impl $Ty {
1195-
/// The smallest value that can be represented by this non-zero
1196-
/// integer type,
1197-
#[doc = concat!("equal to [`", stringify!($Int), "::MIN`].")]
1198-
///
1199-
/// Note: While most integer types are defined for every whole
1200-
/// number between `MIN` and `MAX`, signed non-zero integers are
1201-
/// a special case. They have a "gap" at 0.
1202-
///
1203-
/// # Examples
1204-
///
1205-
/// ```
1206-
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
1207-
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN.get(), ", stringify!($Int), "::MIN);")]
1208-
/// ```
1209-
#[stable(feature = "nonzero_min_max", since = "1.70.0")]
1210-
pub const MIN: Self = Self::new(<$Int>::MIN).unwrap();
1211-
1212-
/// The largest value that can be represented by this non-zero
1213-
/// integer type,
1214-
#[doc = concat!("equal to [`", stringify!($Int), "::MAX`].")]
1215-
///
1216-
/// Note: While most integer types are defined for every whole
1217-
/// number between `MIN` and `MAX`, signed non-zero integers are
1218-
/// a special case. They have a "gap" at 0.
1219-
///
1220-
/// # Examples
1221-
///
1222-
/// ```
1223-
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
1224-
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX.get(), ", stringify!($Int), "::MAX);")]
1225-
/// ```
1226-
#[stable(feature = "nonzero_min_max", since = "1.70.0")]
1227-
pub const MAX: Self = Self::new(<$Int>::MAX).unwrap();
1228-
}
1229-
)+
1230-
}
1231-
}
1232-
1233-
nonzero_min_max_signed! {
1234-
NonZeroI8(i8);
1235-
NonZeroI16(i16);
1236-
NonZeroI32(i32);
1237-
NonZeroI64(i64);
1238-
NonZeroI128(i128);
1239-
NonZeroIsize(isize);
1240-
}
1241-
12421225
macro_rules! nonzero_bits {
12431226
( $( $Ty: ident($Int: ty); )+ ) => {
12441227
$(

0 commit comments

Comments
 (0)