Skip to content

Commit 66cda3b

Browse files
committed
Move signed MIN and MAX into signedness_dependent_methods
1 parent 7f7c5af commit 66cda3b

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
@@ -805,13 +805,47 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
805805
}
806806
};
807807

808-
// Methods for signed nonzero types only.
808+
// Associated items for signed nonzero types only.
809809
(
810810
Self = $Ty:ident,
811811
Primitive = signed $Int:ident,
812812
UnsignedNonZero = $Uty:ident,
813813
UnsignedPrimitive = $Uint:ty,
814814
) => {
815+
/// The smallest value that can be represented by this non-zero
816+
/// integer type,
817+
#[doc = concat!("equal to [`", stringify!($Int), "::MIN`].")]
818+
///
819+
/// Note: While most integer types are defined for every whole
820+
/// number between `MIN` and `MAX`, signed non-zero integers are
821+
/// a special case. They have a "gap" at 0.
822+
///
823+
/// # Examples
824+
///
825+
/// ```
826+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
827+
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN.get(), ", stringify!($Int), "::MIN);")]
828+
/// ```
829+
#[stable(feature = "nonzero_min_max", since = "1.70.0")]
830+
pub const MIN: Self = Self::new(<$Int>::MIN).unwrap();
831+
832+
/// The largest value that can be represented by this non-zero
833+
/// integer type,
834+
#[doc = concat!("equal to [`", stringify!($Int), "::MAX`].")]
835+
///
836+
/// Note: While most integer types are defined for every whole
837+
/// number between `MIN` and `MAX`, signed non-zero integers are
838+
/// a special case. They have a "gap" at 0.
839+
///
840+
/// # Examples
841+
///
842+
/// ```
843+
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
844+
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX.get(), ", stringify!($Int), "::MAX);")]
845+
/// ```
846+
#[stable(feature = "nonzero_min_max", since = "1.70.0")]
847+
pub const MAX: Self = Self::new(<$Int>::MAX).unwrap();
848+
815849
/// Computes the absolute value of self.
816850
#[doc = concat!("See [`", stringify!($Int), "::abs`]")]
817851
/// for documentation on overflow behaviour.
@@ -1202,57 +1236,6 @@ macro_rules! sign_dependent_expr {
12021236
};
12031237
}
12041238

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

0 commit comments

Comments
 (0)