From 7fde7308bf751315e0f4fabe32258916b166e34e Mon Sep 17 00:00:00 2001 From: ivan-shrimp <70307174+ivan-shrimp@users.noreply.github.com> Date: Sun, 12 May 2024 11:29:24 +0800 Subject: [PATCH] reverse condition in `uN::checked_sub` --- library/core/src/num/uint_macros.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 48a96c5792c64..446d0658c1262 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -584,11 +584,11 @@ macro_rules! uint_impl { // Thus, rather than using `overflowing_sub` that produces a wrapping // subtraction, check it ourself so we can use an unchecked one. - if self >= rhs { + if self < rhs { + None + } else { // SAFETY: just checked this can't overflow Some(unsafe { intrinsics::unchecked_sub(self, rhs) }) - } else { - None } }