X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=library%2Fcore%2Fsrc%2Fnum%2Fint_macros.rs;h=b59f28193e2bdc24fddce4bc4ff7b3ed060a6c9e;hb=dc3e59cb3fe05ebd752d3a2269f501c00327be22;hp=2cae98b8e494334e640b3c936181cb1c6db32555;hpb=5610231454f81d09f0a21f7fbdf58ad44898759c;p=rust.git diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 2cae98b8e49..b59f28193e2 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -5,7 +5,7 @@ macro_rules! int_impl { $to_xe_bytes_doc:expr, $from_xe_bytes_doc:expr, $bound_condition:expr) => { /// The smallest value that can be represented by this integer type - #[doc = concat!("(−2", $BITS_MINUS_ONE, "", $bound_condition, ")")] + #[doc = concat!("(−2", $BITS_MINUS_ONE, "", $bound_condition, ").")] /// /// # Examples /// @@ -18,7 +18,7 @@ macro_rules! int_impl { pub const MIN: Self = !0 ^ ((!0 as $UnsignedT) >> 1) as Self; /// The largest value that can be represented by this integer type - #[doc = concat!("(2", $BITS_MINUS_ONE, " − 1", $bound_condition, ")")] + #[doc = concat!("(2", $BITS_MINUS_ONE, " − 1", $bound_condition, ").")] /// /// # Examples /// @@ -2574,12 +2574,13 @@ pub const fn abs_diff(self, other: Self) -> $UnsignedT { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] + #[rustc_allow_const_fn_unstable(const_cmp)] pub const fn signum(self) -> Self { - match self { - n if n > 0 => 1, - 0 => 0, - _ => -1, - } + // Picking the right way to phrase this is complicated + // () + // so delegate it to `Ord` which is already producing -1/0/+1 + // exactly like we need and can be the place to deal with the complexity. + self.cmp(&0) as _ } /// Returns `true` if `self` is positive and `false` if the number is zero or