From 0c843613423cdd6fdf8d8efe462bfc66640c14f2 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 25 May 2024 15:58:26 -0700 Subject: [PATCH] Simplify the `unchecked_sh[lr]` ub-checks a bit --- library/core/src/num/int_macros.rs | 6 ++---- library/core/src/num/uint_macros.rs | 6 ++---- ...s.unchecked_shl_unsigned_smaller.Inline.panic-abort.diff | 2 +- ....unchecked_shl_unsigned_smaller.Inline.panic-unwind.diff | 2 +- ...ifts.unchecked_shr_signed_bigger.Inline.panic-abort.diff | 2 +- ...fts.unchecked_shr_signed_bigger.Inline.panic-unwind.diff | 2 +- 6 files changed, 8 insertions(+), 12 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index b8b4f581a7e..c9c6e34eaad 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -1282,8 +1282,7 @@ pub const fn strict_shl(self, rhs: u32) -> Self { concat!(stringify!($SelfT), "::unchecked_shl cannot overflow"), ( rhs: u32 = rhs, - bits: u32 = Self::BITS, - ) => rhs < bits, + ) => rhs < <$ActualT>::BITS, ); // SAFETY: this is guaranteed to be safe by the caller. @@ -1381,8 +1380,7 @@ pub const fn strict_shr(self, rhs: u32) -> Self { concat!(stringify!($SelfT), "::unchecked_shr cannot overflow"), ( rhs: u32 = rhs, - bits: u32 = Self::BITS, - ) => rhs < bits, + ) => rhs < <$ActualT>::BITS, ); // SAFETY: this is guaranteed to be safe by the caller. diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 141d164de14..f70c34199ac 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1369,8 +1369,7 @@ pub const fn strict_shl(self, rhs: u32) -> Self { concat!(stringify!($SelfT), "::unchecked_shl cannot overflow"), ( rhs: u32 = rhs, - bits: u32 = Self::BITS, - ) => rhs < bits, + ) => rhs < <$ActualT>::BITS, ); // SAFETY: this is guaranteed to be safe by the caller. @@ -1468,8 +1467,7 @@ pub const fn strict_shr(self, rhs: u32) -> Self { concat!(stringify!($SelfT), "::unchecked_shr cannot overflow"), ( rhs: u32 = rhs, - bits: u32 = Self::BITS, - ) => rhs < bits, + ) => rhs < <$ActualT>::BITS, ); // SAFETY: this is guaranteed to be safe by the caller. diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-abort.diff b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-abort.diff index 652e24a5f8e..0d9d58316ea 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-abort.diff @@ -29,7 +29,7 @@ } bb1: { -+ _6 = core::num::::unchecked_shl::precondition_check(_4, const core::num::::BITS) -> [return: bb2, unwind unreachable]; ++ _6 = core::num::::unchecked_shl::precondition_check(_4) -> [return: bb2, unwind unreachable]; + } + + bb2: { diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-unwind.diff b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-unwind.diff index dbcae605f76..82f7eceaa18 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-unwind.diff @@ -29,7 +29,7 @@ } bb1: { -+ _6 = core::num::::unchecked_shl::precondition_check(_4, const core::num::::BITS) -> [return: bb2, unwind unreachable]; ++ _6 = core::num::::unchecked_shl::precondition_check(_4) -> [return: bb2, unwind unreachable]; + } + + bb2: { diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-abort.diff b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-abort.diff index 88d0621c287..6894b246699 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-abort.diff @@ -29,7 +29,7 @@ } bb1: { -+ _6 = core::num::::unchecked_shr::precondition_check(_4, const core::num::::BITS) -> [return: bb2, unwind unreachable]; ++ _6 = core::num::::unchecked_shr::precondition_check(_4) -> [return: bb2, unwind unreachable]; + } + + bb2: { diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-unwind.diff b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-unwind.diff index 6d4c73cf576..070f4a1c5c8 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-unwind.diff @@ -29,7 +29,7 @@ } bb1: { -+ _6 = core::num::::unchecked_shr::precondition_check(_4, const core::num::::BITS) -> [return: bb2, unwind unreachable]; ++ _6 = core::num::::unchecked_shr::precondition_check(_4) -> [return: bb2, unwind unreachable]; + } + + bb2: {