Skip to content

Commit

Permalink
Rollup merge of rust-lang#125559 - scottmcm:simplify-shift-ubcheck, r…
Browse files Browse the repository at this point in the history
…=workingjubilee

Simplify the `unchecked_sh[lr]` ub-checks a bit

It can use the constant in the check, rather than passing it as a parameter.
  • Loading branch information
matthiaskrgr authored May 26, 2024
2 parents 5c291a1 + 0c84361 commit c35e2ce
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 12 deletions.
6 changes: 2 additions & 4 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,8 +1282,7 @@ macro_rules! int_impl {
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.
Expand Down Expand Up @@ -1381,8 +1380,7 @@ macro_rules! int_impl {
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.
Expand Down
6 changes: 2 additions & 4 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1369,8 +1369,7 @@ macro_rules! uint_impl {
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.
Expand Down Expand Up @@ -1468,8 +1467,7 @@ macro_rules! uint_impl {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

bb1: {
+ _6 = core::num::<impl u16>::unchecked_shl::precondition_check(_4, const core::num::<impl u16>::BITS) -> [return: bb2, unwind unreachable];
+ _6 = core::num::<impl u16>::unchecked_shl::precondition_check(_4) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

bb1: {
+ _6 = core::num::<impl u16>::unchecked_shl::precondition_check(_4, const core::num::<impl u16>::BITS) -> [return: bb2, unwind unreachable];
+ _6 = core::num::<impl u16>::unchecked_shl::precondition_check(_4) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

bb1: {
+ _6 = core::num::<impl i64>::unchecked_shr::precondition_check(_4, const core::num::<impl i64>::BITS) -> [return: bb2, unwind unreachable];
+ _6 = core::num::<impl i64>::unchecked_shr::precondition_check(_4) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

bb1: {
+ _6 = core::num::<impl i64>::unchecked_shr::precondition_check(_4, const core::num::<impl i64>::BITS) -> [return: bb2, unwind unreachable];
+ _6 = core::num::<impl i64>::unchecked_shr::precondition_check(_4) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
Expand Down

0 comments on commit c35e2ce

Please sign in to comment.