X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=library%2Fcore%2Fsrc%2Fnum%2Fint_macros.rs;h=acd0fea4bc4105a03a1d793098e0a45a866a5166;hb=77e78e28870a3241deadc28e14ba82e9f8548802;hp=2cae98b8e494334e640b3c936181cb1c6db32555;hpb=94a300b9b8eb253c1b809fc44b8c213fd591c537;p=rust.git diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 2cae98b8e49..acd0fea4bc4 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -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