Skip to content

Commit e80c020

Browse files
committed
more hacks
1 parent ddc02b0 commit e80c020

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

library/core/src/num/int_macros.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,8 @@ macro_rules! int_impl {
785785
// SAFETY: the caller must uphold the safety contract for
786786
// `unchecked_shl`.
787787
// Any legal shift amount is losslessly representable in the self type.
788-
unsafe { intrinsics::unchecked_shl(self, rhs.try_into().ok().unwrap_unchecked()) }
788+
// FIXME(const-hack) replace with `.try_into().ok().unwrap_unchecked()`.
789+
unsafe { intrinsics::unchecked_shl(self, rhs as _) }
789790
}
790791

791792
/// Checked shift right. Computes `self >> rhs`, returning `None` if `rhs` is
@@ -833,7 +834,8 @@ macro_rules! int_impl {
833834
// SAFETY: the caller must uphold the safety contract for
834835
// `unchecked_shr`.
835836
// Any legal shift amount is losslessly representable in the self type.
836-
unsafe { intrinsics::unchecked_shr(self, rhs.try_into().ok().unwrap_unchecked()) }
837+
// FIXME(const-hack) replace with `.try_into().ok().unwrap_unchecked()`.
838+
unsafe { intrinsics::unchecked_shr(self, rhs as _) }
837839
}
838840

839841
/// Checked absolute value. Computes `self.abs()`, returning `None` if

library/core/src/num/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![stable(feature = "rust1", since = "1.0.0")]
44

55
use crate::ascii;
6-
use crate::convert::TryInto;
76
use crate::intrinsics;
87
use crate::mem;
98
use crate::ops::{Add, Mul, Sub};

library/core/src/num/uint_macros.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,8 @@ macro_rules! uint_impl {
939939
// SAFETY: the caller must uphold the safety contract for
940940
// `unchecked_shl`.
941941
// Any legal shift amount is losslessly representable in the self type.
942-
unsafe { intrinsics::unchecked_shl(self, rhs.try_into().ok().unwrap_unchecked()) }
942+
// FIXME(const-hack) replace with `.try_into().ok().unwrap_unchecked()`.
943+
unsafe { intrinsics::unchecked_shl(self, rhs as _) }
943944
}
944945

945946
/// Checked shift right. Computes `self >> rhs`, returning `None`
@@ -987,7 +988,8 @@ macro_rules! uint_impl {
987988
// SAFETY: the caller must uphold the safety contract for
988989
// `unchecked_shr`.
989990
// Any legal shift amount is losslessly representable in the self type.
990-
unsafe { intrinsics::unchecked_shr(self, rhs.try_into().ok().unwrap_unchecked()) }
991+
// FIXME(const-hack) replace with `.try_into().ok().unwrap_unchecked()`.
992+
unsafe { intrinsics::unchecked_shr(self, rhs as _) }
991993
}
992994

993995
/// Checked exponentiation. Computes `self.pow(exp)`, returning `None` if

library/core/src/ptr/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,12 @@ pub(crate) const unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usiz
17641764
// miracles, given the situations this case has to deal with.
17651765

17661766
// SAFETY: a is power-of-two hence non-zero. stride == 0 case is handled above.
1767-
let gcdpow = unsafe { cttz_nonzero(stride).min(cttz_nonzero(a)) };
1767+
// FIXME(const-hack) replace with min
1768+
let gcdpow = unsafe {
1769+
let x = cttz_nonzero(stride);
1770+
let y = cttz_nonzero(a);
1771+
if x < y { x } else { y }
1772+
};
17681773
// SAFETY: gcdpow has an upper-bound that’s at most the number of bits in a usize.
17691774
let gcd = unsafe { unchecked_shl(1usize, gcdpow) };
17701775
// SAFETY: gcd is always greater or equal to 1.

0 commit comments

Comments
 (0)