more hacks

This commit is contained in:
Deadbeef 2023-04-16 07:20:15 +00:00
parent ddc02b0f32
commit e80c020445
4 changed files with 14 additions and 6 deletions

View File

@ -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

View File

@ -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};

View File

@ -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

View File

@ -1764,7 +1764,12 @@ pub(crate) const unsafe fn align_offset<T: Sized>(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 thats 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.