Skip to content

Commit 6db7e34

Browse files
committed
use integer assoc consts instead of methods
1 parent 7a3700c commit 6db7e34

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

src/librustc/mir/interpret/allocation.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -818,9 +818,9 @@ impl UndefMask {
818818
// First set all bits except the first `bita`,
819819
// then unset the last `64 - bitb` bits.
820820
let range = if bitb == 0 {
821-
u64::max_value() << bita
821+
u64::MAX << bita
822822
} else {
823-
(u64::max_value() << bita) & (u64::max_value() >> (64 - bitb))
823+
(u64::MAX << bita) & (u64::MAX >> (64 - bitb))
824824
};
825825
if new_state {
826826
self.blocks[blocka] |= range;
@@ -832,21 +832,21 @@ impl UndefMask {
832832
// across block boundaries
833833
if new_state {
834834
// Set `bita..64` to `1`.
835-
self.blocks[blocka] |= u64::max_value() << bita;
835+
self.blocks[blocka] |= u64::MAX << bita;
836836
// Set `0..bitb` to `1`.
837837
if bitb != 0 {
838-
self.blocks[blockb] |= u64::max_value() >> (64 - bitb);
838+
self.blocks[blockb] |= u64::MAX >> (64 - bitb);
839839
}
840840
// Fill in all the other blocks (much faster than one bit at a time).
841841
for block in (blocka + 1)..blockb {
842-
self.blocks[block] = u64::max_value();
842+
self.blocks[block] = u64::MAX;
843843
}
844844
} else {
845845
// Set `bita..64` to `0`.
846-
self.blocks[blocka] &= !(u64::max_value() << bita);
846+
self.blocks[blocka] &= !(u64::MAX << bita);
847847
// Set `0..bitb` to `0`.
848848
if bitb != 0 {
849-
self.blocks[blockb] &= !(u64::max_value() >> (64 - bitb));
849+
self.blocks[blockb] &= !(u64::MAX >> (64 - bitb));
850850
}
851851
// Fill in all the other blocks (much faster than one bit at a time).
852852
for block in (blocka + 1)..blockb {

src/librustc/mir/interpret/pointer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ pub trait PointerArithmetic: layout::HasDataLayout {
7878
fn overflowing_signed_offset(&self, val: u64, i: i128) -> (u64, bool) {
7979
// FIXME: is it possible to over/underflow here?
8080
if i < 0 {
81-
// Trickery to ensure that `i64::min_value()` works fine: compute `n = -i`.
81+
// Trickery to ensure that `i64::MIN` works fine: compute `n = -i`.
8282
// This formula only works for true negative values; it overflows for zero!
83-
let n = u64::max_value() - (i as u64) + 1;
83+
let n = u64::MAX - (i as u64) + 1;
8484
let res = val.overflowing_sub(n);
8585
self.truncate_to_ptr(res)
8686
} else {

src/librustc_mir/interpret/intrinsics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
203203
if is_add {
204204
// max unsigned
205205
Scalar::from_uint(
206-
u128::max_value() >> (128 - num_bits),
206+
u128::MAX >> (128 - num_bits),
207207
Size::from_bits(num_bits),
208208
)
209209
} else {
@@ -381,11 +381,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
381381
dest: PlaceTy<'tcx, M::PointerTag>,
382382
) -> InterpResult<'tcx> {
383383
// Performs an exact division, resulting in undefined behavior where
384-
// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`.
384+
// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`.
385385
// First, check x % y != 0 (or if that computation overflows).
386386
let (res, overflow, _ty) = self.overflowing_binary_op(BinOp::Rem, a, b)?;
387387
if overflow || res.assert_bits(a.layout.size) != 0 {
388-
// Then, check if `b` is -1, which is the "min_value / -1" case.
388+
// Then, check if `b` is -1, which is the "MIN / -1" case.
389389
let minus1 = Scalar::from_int(-1, dest.layout.size);
390390
let b_scalar = b.to_scalar().unwrap();
391391
if b_scalar == minus1 {

src/librustc_mir/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
463463
let (lo, hi) = valid_range.clone().into_inner();
464464
// Determine the allowed range
465465
// `max_hi` is as big as the size fits
466-
let max_hi = u128::max_value() >> (128 - op.layout.size.bits());
466+
let max_hi = u128::MAX >> (128 - op.layout.size.bits());
467467
assert!(hi <= max_hi);
468468
// We could also write `(hi + 1) % (max_hi + 1) == lo` but `max_hi + 1` overflows for `u128`
469469
if (lo == 0 && hi == max_hi) || (hi + 1 == lo) {

0 commit comments

Comments
 (0)