From e80c0204455534c5d9ec4f92dd8bffd392513fc3 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 16 Apr 2023 07:20:15 +0000 Subject: [PATCH] more hacks --- library/core/src/num/int_macros.rs | 6 ++++-- library/core/src/num/mod.rs | 1 - library/core/src/num/uint_macros.rs | 6 ++++-- library/core/src/ptr/mod.rs | 7 ++++++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index d645e8dcbfd..1e82d4d1ff0 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -785,7 +785,8 @@ macro_rules! int_impl { // SAFETY: the caller must uphold the safety contract for // `unchecked_shl`. // Any legal shift amount is losslessly representable in the self type. - unsafe { intrinsics::unchecked_shl(self, rhs.try_into().ok().unwrap_unchecked()) } + // FIXME(const-hack) replace with `.try_into().ok().unwrap_unchecked()`. + unsafe { intrinsics::unchecked_shl(self, rhs as _) } } /// Checked shift right. Computes `self >> rhs`, returning `None` if `rhs` is @@ -833,7 +834,8 @@ macro_rules! int_impl { // SAFETY: the caller must uphold the safety contract for // `unchecked_shr`. // Any legal shift amount is losslessly representable in the self type. - unsafe { intrinsics::unchecked_shr(self, rhs.try_into().ok().unwrap_unchecked()) } + // FIXME(const-hack) replace with `.try_into().ok().unwrap_unchecked()`. + unsafe { intrinsics::unchecked_shr(self, rhs as _) } } /// Checked absolute value. Computes `self.abs()`, returning `None` if diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 9b812bbfc23..b0488dc069b 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -3,7 +3,6 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::ascii; -use crate::convert::TryInto; use crate::intrinsics; use crate::mem; use crate::ops::{Add, Mul, Sub}; diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 114deeea387..795645b8b7b 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -939,7 +939,8 @@ macro_rules! uint_impl { // SAFETY: the caller must uphold the safety contract for // `unchecked_shl`. // Any legal shift amount is losslessly representable in the self type. - unsafe { intrinsics::unchecked_shl(self, rhs.try_into().ok().unwrap_unchecked()) } + // FIXME(const-hack) replace with `.try_into().ok().unwrap_unchecked()`. + unsafe { intrinsics::unchecked_shl(self, rhs as _) } } /// Checked shift right. Computes `self >> rhs`, returning `None` @@ -987,7 +988,8 @@ macro_rules! uint_impl { // SAFETY: the caller must uphold the safety contract for // `unchecked_shr`. // Any legal shift amount is losslessly representable in the self type. - unsafe { intrinsics::unchecked_shr(self, rhs.try_into().ok().unwrap_unchecked()) } + // FIXME(const-hack) replace with `.try_into().ok().unwrap_unchecked()`. + unsafe { intrinsics::unchecked_shr(self, rhs as _) } } /// Checked exponentiation. Computes `self.pow(exp)`, returning `None` if diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 818f1a919d0..555d58fad84 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -1764,7 +1764,12 @@ pub(crate) const unsafe fn align_offset(p: *const T, a: usize) -> usiz // miracles, given the situations this case has to deal with. // SAFETY: a is power-of-two hence non-zero. stride == 0 case is handled above. - let gcdpow = unsafe { cttz_nonzero(stride).min(cttz_nonzero(a)) }; + // FIXME(const-hack) replace with min + let gcdpow = unsafe { + let x = cttz_nonzero(stride); + let y = cttz_nonzero(a); + if x < y { x } else { y } + }; // SAFETY: gcdpow has an upper-bound that’s at most the number of bits in a usize. let gcd = unsafe { unchecked_shl(1usize, gcdpow) }; // SAFETY: gcd is always greater or equal to 1.