Skip to content

Commit 148269d

Browse files
committed
finally stop using min/max_value and the integer modules
1 parent 974c8be commit 148269d

16 files changed

+31
-37
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4d71c164a89b705df6affd31a5262c832d1bc48d
1+
7a3700c37132385e8e965c18e73d0a09f9146335

src/shims/foreign_items.rs

Lines changed: 4 additions & 4 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 7 deletions
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

0 commit comments

Comments
 (0)