From 4846fd92c0cc82545c5fd33c9ab3007f03f0f9f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Sun, 3 Oct 2021 22:56:34 +0200 Subject: [PATCH] Revert suggested use of `unwrap_or` --- library/core/src/num/int_macros.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 540b7d36625..5bdb6ed9176 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -885,7 +885,11 @@ macro_rules! int_impl { #[inline] pub const fn saturating_add_unsigned(self, rhs: $UnsignedT) -> Self { // Overflow can only happen at the upper bound - self.checked_add_unsigned(rhs).unwrap_or(Self::MAX) + // We cannot use `unwrap_or` here because it is not `const` + match self.checked_add_unsigned(rhs) { + Some(x) => x, + None => Self::MAX, + } } /// Saturating integer subtraction. Computes `self - rhs`, saturating at the @@ -928,7 +932,11 @@ macro_rules! int_impl { #[inline] pub const fn saturating_sub_unsigned(self, rhs: $UnsignedT) -> Self { // Overflow can only happen at the lower bound - self.checked_sub_unsigned(rhs).unwrap_or(Self::MIN) + // We cannot use `unwrap_or` here because it is not `const` + match self.checked_sub_unsigned(rhs) { + Some(x) => x, + None => Self::MIN, + } } /// Saturating integer negation. Computes `-self`, returning `MAX` if `self == MIN`