Skip to content

Commit b5c1fe1

Browse files
committed
nonzero min and nonzero max working.
1 parent 0156ef1 commit b5c1fe1

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

library/core/src/num/nonzero.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -896,22 +896,41 @@ macro_rules! nonzero_unsigned_is_power_of_two {
896896

897897
nonzero_unsigned_is_power_of_two! { NonZeroU8 NonZeroU16 NonZeroU32 NonZeroU64 NonZeroU128 NonZeroUsize }
898898

899-
macro_rules! nonzero_max {
900-
( $( $Ty: ident($Int: ty) )+ ) => {
899+
macro_rules! nonzero_min_max {
900+
( $( $min:expr , $Ty: ident($Int: ty); )+ ) => {
901901
$(
902902

903903
impl $Ty {
904904
#[unstable(feature = "nonzero_max", issue = "89065")]
905905
#[doc = concat!("The maximum value for a`", stringify!($Ty), "` is the same as `", stringify!($Int), "`")]
906-
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX, ", stringify!($Int), ">::MAX);")]
906+
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX, ", stringify!($Int), "::MAX);")]
907907
//SAFETY: Since the MAX value, for any supported integer type, is greater than 0,
908908
// the MAX will always be non-zero.
909909
pub const MAX : $Ty = unsafe { $Ty::new_unchecked(<$Int>::MAX) };
910-
}
910+
#[unstable(feature = "nonzero_min", issue = "89065")]
911+
#[doc = concat!("The minimum value for a`", stringify!($Ty), "`.")]
912+
/// # Examples
913+
///
914+
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN, ", stringify!($min), ";")]
915+
//SAFETY: In the signed case, the minimum integer is negative, and therefore non-zero.
916+
// In the unsignedd case, we use one, which is non-zero.
917+
pub const MIN : $Ty = unsafe { $Ty::new_unchecked($min)};
918+
}
911919
)+
912920
}
913921
}
914922

915-
nonzero_max! { NonZeroU8(u8) NonZeroI8(i8) NonZeroU16(u16) NonZeroI16(i16) NonZeroU32(u32) NonZeroI32(i32)
916-
NonZeroU64(u64) NonZeroI64(i64) NonZeroUsize(usize) NonZeroIsize(isize)
923+
nonzero_min_max! {
924+
1 , NonZeroU8(u8);
925+
1 , NonZeroU16(u16);
926+
1 , NonZeroU32(u32);
927+
1 , NonZeroU64(u64);
928+
1 , NonZeroU128(u128);
929+
1 , NonZeroUsize(usize);
930+
i8::MIN , NonZeroI8(i8);
931+
i16::MIN , NonZeroI16(i16);
932+
i32::MIN , NonZeroI32(i32);
933+
i64::MIN , NonZeroI64(i64);
934+
i128::MIN , NonZeroI128(i128);
935+
isize::MIN , NonZeroIsize(isize);
917936
}

0 commit comments

Comments
 (0)