Skip to content

Commit 6392516

Browse files
committed
Auto merge of #1206 - RalfJung:int_asooc, r=RalfJung
finally stop using min/max_value and the integer modules rust-lang/rust#68952 landed, so we can finally do this :)
2 parents 974c8be + 148269d commit 6392516

16 files changed

+31
-37
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4d71c164a89b705df6affd31a5262c832d1bc48d
1+
7a3700c37132385e8e965c18e73d0a09f9146335

src/shims/foreign_items.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
443443

444444
// Saturating cast to i16. Even those are outside the valid exponent range to
445445
// `scalbn` below will do its over/underflow handling.
446-
let exp = if exp > i16::max_value() as i32 {
447-
i16::max_value()
448-
} else if exp < i16::min_value() as i32 {
449-
i16::min_value()
446+
let exp = if exp > i16::MAX as i32 {
447+
i16::MAX
448+
} else if exp < i16::MIN as i32 {
449+
i16::MIN
450450
} else {
451451
exp.try_into().unwrap()
452452
};

src/shims/fs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
427427

428428
// We cap the number of read bytes to the largest value that we are able to fit in both the
429429
// host's and target's `isize`. This saves us from having to handle overflows later.
430-
let count = count.min(this.isize_max() as u64).min(isize::max_value() as u64);
430+
let count = count.min(this.isize_max() as u64).min(isize::MAX as u64);
431431

432432
if let Some(FileHandle { file, writable: _ }) = this.machine.file_handler.handles.get_mut(&fd) {
433433
// This can never fail because `count` was capped to be smaller than
434-
// `isize::max_value()`.
434+
// `isize::MAX`.
435435
let count = isize::try_from(count).unwrap();
436436
// We want to read at most `count` bytes. We are sure that `count` is not negative
437437
// because it was a target's `usize`. Also we are sure that its smaller than
438-
// `usize::max_value()` because it is a host's `isize`.
438+
// `usize::MAX` because it is a host's `isize`.
439439
let mut bytes = vec![0; count as usize];
440440
let result = file
441441
.read(&mut bytes)
@@ -481,7 +481,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
481481

482482
// We cap the number of written bytes to the largest value that we are able to fit in both the
483483
// host's and target's `isize`. This saves us from having to handle overflows later.
484-
let count = count.min(this.isize_max() as u64).min(isize::max_value() as u64);
484+
let count = count.min(this.isize_max() as u64).min(isize::MAX as u64);
485485

486486
if let Some(FileHandle { file, writable: _ }) = this.machine.file_handler.handles.get_mut(&fd) {
487487
let bytes = this.memory.read_bytes(buf, Size::from_bytes(count))?;

src/shims/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2727
let (dest, ret) = ret.unwrap();
2828
let n = this
2929
.align_offset(args[0], args[1])?
30-
.unwrap_or_else(|| this.truncate(u128::max_value(), dest.layout));
30+
.unwrap_or_else(|| this.truncate(u128::MAX, dest.layout));
3131
this.write_scalar(Scalar::from_uint(n, dest.layout.size), dest)?;
3232
this.go_to_block(ret);
3333
return Ok(None);

tests/compile-fail/exact_div4.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(core_intrinsics)]
22
fn main() {
3-
// divison of min_value by -1
4-
unsafe { std::intrinsics::exact_div(i64::min_value(), -1); } //~ ERROR result of dividing MIN by -1 cannot be represented
3+
// divison of MIN by -1
4+
unsafe { std::intrinsics::exact_div(i64::MIN, -1); } //~ ERROR result of dividing MIN by -1 cannot be represented
55
}

tests/compile-fail/ptr_offset_overflow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
fn main() {
33
let v = [1i8, 2];
44
let x = &v[1] as *const i8;
5-
let _val = unsafe { x.offset(isize::min_value()) };
5+
let _val = unsafe { x.offset(isize::MIN) };
66
}

tests/compile-fail/slice-too-big.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::mem;
2-
use std::usize;
32

43
fn main() { unsafe {
54
let ptr = Box::into_raw(Box::new(0u8));

tests/compile-fail/unchecked_div1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(core_intrinsics)]
22
fn main() {
33
// MIN/-1 cannot be represented
4-
unsafe { std::intrinsics::unchecked_div(i16::min_value(), -1); } //~ ERROR Overflow executing `unchecked_div`
4+
unsafe { std::intrinsics::unchecked_div(i16::MIN, -1); } //~ ERROR Overflow executing `unchecked_div`
55
}

tests/run-pass/align_offset.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ fn test_align_offset() {
55

66
assert_eq!(raw.align_offset(2), 0);
77
assert_eq!(raw.align_offset(4), 0);
8-
assert_eq!(raw.align_offset(8), usize::max_value()); // requested alignment higher than allocation alignment
8+
assert_eq!(raw.align_offset(8), usize::MAX); // requested alignment higher than allocation alignment
99

1010
assert_eq!(raw.wrapping_offset(1).align_offset(2), 1);
1111
assert_eq!(raw.wrapping_offset(1).align_offset(4), 3);
12-
assert_eq!(raw.wrapping_offset(1).align_offset(8), usize::max_value()); // requested alignment higher than allocation alignment
12+
assert_eq!(raw.wrapping_offset(1).align_offset(8), usize::MAX); // requested alignment higher than allocation alignment
1313

1414
assert_eq!(raw.wrapping_offset(2).align_offset(2), 0);
1515
assert_eq!(raw.wrapping_offset(2).align_offset(4), 2);
16-
assert_eq!(raw.wrapping_offset(2).align_offset(8), usize::max_value()); // requested alignment higher than allocation alignment
16+
assert_eq!(raw.wrapping_offset(2).align_offset(8), usize::MAX); // requested alignment higher than allocation alignment
1717
}
1818

1919
fn test_align_to() {

tests/run-pass/integer-ops.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::i32;
12-
1311
pub fn main() {
1412
// This tests that do (not) do sign extension properly when loading integers
15-
assert_eq!(u32::max_value() as i64, 4294967295);
16-
assert_eq!(i32::min_value() as i64, -2147483648);
17-
18-
assert_eq!(i8::min_value(), -128);
13+
assert_eq!(u32::MAX as i64, 4294967295);
14+
assert_eq!(i32::MIN as i64, -2147483648);
1915

20-
assert_eq!(i8::max_value(), 127);
16+
assert_eq!(i8::MAX, 127);
17+
assert_eq!(i8::MIN, -128);
2118

2219
assert_eq!(i32::from_str_radix("A", 16), Ok(10));
2320

tests/run-pass/ints.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ fn main() {
5151
assert_eq!(arith(), 5*5);
5252
assert_eq!(match_int(), 20);
5353
assert_eq!(match_int_range(), 4);
54-
assert_eq!(i64::min_value().overflowing_mul(-1), (i64::min_value(), true));
55-
assert_eq!(i32::min_value().overflowing_mul(-1), (i32::min_value(), true));
56-
assert_eq!(i16::min_value().overflowing_mul(-1), (i16::min_value(), true));
57-
assert_eq!(i8::min_value().overflowing_mul(-1), (i8::min_value(), true));
54+
assert_eq!(i64::MIN.overflowing_mul(-1), (i64::MIN, true));
55+
assert_eq!(i32::MIN.overflowing_mul(-1), (i32::MIN, true));
56+
assert_eq!(i16::MIN.overflowing_mul(-1), (i16::MIN, true));
57+
assert_eq!(i8::MIN.overflowing_mul(-1), (i8::MIN, true));
5858
}

tests/run-pass/panic/overflowing-rsh-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
fn main() {
55
// Make sure we catch overflows that would be hidden by first casting the RHS to u32
6-
let _n = 1i64 >> (u32::max_value() as i64 + 1);
6+
let _n = 1i64 >> (u32::MAX as i64 + 1);
77
}

tests/run-pass/pointers.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::usize;
2-
31
fn one_line_ref() -> i16 {
42
*&1
53
}

tests/run-pass/ptr_arith_offset_overflow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ fn main() {
55
let x = &mut ptr::null(); // going through memory as there are more sanity checks along that path
66
*x = v.as_ptr().wrapping_offset(1); // ptr to the 2nd element
77
// Adding 2*isize::max and then 1 is like substracting 1
8-
*x = x.wrapping_offset(isize::max_value());
9-
*x = x.wrapping_offset(isize::max_value());
8+
*x = x.wrapping_offset(isize::MAX);
9+
*x = x.wrapping_offset(isize::MAX);
1010
*x = x.wrapping_offset(1);
1111
assert_eq!(unsafe { **x }, 1);
1212
}

tests/run-pass/ptr_int_casts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
// this used to trigger an ICE on 32bit)
1717
let val = &mut ptr::null();
1818
*val = (1 as *const u8).wrapping_offset(-4);
19-
assert_eq!(*val as usize, usize::max_value() - 2);
19+
assert_eq!(*val as usize, usize::MAX - 2);
2020

2121
{ // ptr-int-ptr
2222
let x = 13;

tests/run-pass/u128.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ fn main() {
4848
assert_eq!("10000000000000000000000000000000000000000000000000000000000000000000",
4949
format!("{:b}", j));
5050
assert_eq!("340282366920938463463374607431768211455",
51-
format!("{}", u128::max_value()));
51+
format!("{}", u128::MAX));
5252
assert_eq!("147573952589676412928", format!("{:?}", j));
5353
// common traits
5454
assert_eq!(x, b(x.clone()));
5555
// overflow checks
5656
assert_eq!((z).checked_mul(z), Some(0x734C_C2F2_A521));
5757
assert_eq!((k).checked_mul(k), None);
58-
let l: u128 = b(u128::max_value() - 10);
58+
let l: u128 = b(u128::MAX - 10);
5959
let o: u128 = b(17);
6060
assert_eq!(l.checked_add(b(11)), None);
6161
assert_eq!(l.checked_sub(l), Some(0));

0 commit comments

Comments
 (0)