Skip to content

Commit 5f687fb

Browse files
committed
Replace all usages of min_value/max_value with assoc const MIN/MAX
1 parent c127d8f commit 5f687fb

File tree

93 files changed

+360
-381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+360
-381
lines changed

src/liballoc/rc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ trait RcBoxPtr<T: ?Sized> {
19971997
// The reference count will never be zero when this is called;
19981998
// nevertheless, we insert an abort here to hint LLVM at
19991999
// an otherwise missed optimization.
2000-
if strong == 0 || strong == usize::max_value() {
2000+
if strong == 0 || strong == usize::MAX {
20012001
unsafe {
20022002
abort();
20032003
}
@@ -2023,7 +2023,7 @@ trait RcBoxPtr<T: ?Sized> {
20232023
// The reference count will never be zero when this is called;
20242024
// nevertheless, we insert an abort here to hint LLVM at
20252025
// an otherwise missed optimization.
2026-
if weak == 0 || weak == usize::max_value() {
2026+
if weak == 0 || weak == usize::MAX {
20272027
unsafe {
20282028
abort();
20292029
}

src/liballoc/rc/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,14 @@ fn test_from_vec() {
407407
fn test_downcast() {
408408
use std::any::Any;
409409

410-
let r1: Rc<dyn Any> = Rc::new(i32::max_value());
410+
let r1: Rc<dyn Any> = Rc::new(i32::MAX);
411411
let r2: Rc<dyn Any> = Rc::new("abc");
412412

413413
assert!(r1.clone().downcast::<u32>().is_err());
414414

415415
let r1i32 = r1.downcast::<i32>();
416416
assert!(r1i32.is_ok());
417-
assert_eq!(r1i32.unwrap(), Rc::new(i32::max_value()));
417+
assert_eq!(r1i32.unwrap(), Rc::new(i32::MAX));
418418

419419
assert!(r2.clone().downcast::<i32>().is_err());
420420

src/liballoc/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ impl<T> [T] {
433433
///
434434
/// ```should_panic
435435
/// // this will panic at runtime
436-
/// b"0123456789abcdef".repeat(usize::max_value());
436+
/// b"0123456789abcdef".repeat(usize::MAX);
437437
/// ```
438438
#[stable(feature = "repeat_generic_slice", since = "1.40.0")]
439439
pub fn repeat(&self, n: usize) -> Vec<T>

src/liballoc/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl str {
499499
///
500500
/// ```should_panic
501501
/// // this will panic at runtime
502-
/// "0123456789abcdef".repeat(usize::max_value());
502+
/// "0123456789abcdef".repeat(usize::MAX);
503503
/// ```
504504
#[stable(feature = "repeat_str", since = "1.16.0")]
505505
pub fn repeat(&self, n: usize) -> String {

src/liballoc/sync/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,14 @@ fn test_from_vec() {
463463
fn test_downcast() {
464464
use std::any::Any;
465465

466-
let r1: Arc<dyn Any + Send + Sync> = Arc::new(i32::max_value());
466+
let r1: Arc<dyn Any + Send + Sync> = Arc::new(i32::MAX);
467467
let r2: Arc<dyn Any + Send + Sync> = Arc::new("abc");
468468

469469
assert!(r1.clone().downcast::<u32>().is_err());
470470

471471
let r1i32 = r1.downcast::<i32>();
472472
assert!(r1i32.is_ok());
473-
assert_eq!(r1i32.unwrap(), Arc::new(i32::max_value()));
473+
assert_eq!(r1i32.unwrap(), Arc::new(i32::MAX));
474474

475475
assert!(r2.clone().downcast::<i32>().is_err());
476476

src/liballoc/tests/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,13 +566,13 @@ mod slice_index {
566566
data: "hello";
567567
// note: using 0 specifically ensures that the result of overflowing is 0..0,
568568
// so that `get` doesn't simply return None for the wrong reason.
569-
bad: data[0..=usize::max_value()];
569+
bad: data[0..=usize::MAX];
570570
message: "maximum usize";
571571
}
572572

573573
in mod rangetoinclusive {
574574
data: "hello";
575-
bad: data[..=usize::max_value()];
575+
bad: data[..=usize::MAX];
576576
message: "maximum usize";
577577
}
578578
}

src/liballoc/tests/vec.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn test_reserve() {
6868

6969
#[test]
7070
fn test_zst_capacity() {
71-
assert_eq!(Vec::<()>::new().capacity(), usize::max_value());
71+
assert_eq!(Vec::<()>::new().capacity(), usize::MAX);
7272
}
7373

7474
#[test]
@@ -563,19 +563,19 @@ fn test_drain_inclusive_range() {
563563

564564
#[test]
565565
fn test_drain_max_vec_size() {
566-
let mut v = Vec::<()>::with_capacity(usize::max_value());
566+
let mut v = Vec::<()>::with_capacity(usize::MAX);
567567
unsafe {
568-
v.set_len(usize::max_value());
568+
v.set_len(usize::MAX);
569569
}
570-
for _ in v.drain(usize::max_value() - 1..) {}
571-
assert_eq!(v.len(), usize::max_value() - 1);
570+
for _ in v.drain(usize::MAX - 1..) {}
571+
assert_eq!(v.len(), usize::MAX - 1);
572572

573-
let mut v = Vec::<()>::with_capacity(usize::max_value());
573+
let mut v = Vec::<()>::with_capacity(usize::MAX);
574574
unsafe {
575-
v.set_len(usize::max_value());
575+
v.set_len(usize::MAX);
576576
}
577-
for _ in v.drain(usize::max_value() - 1..=usize::max_value() - 1) {}
578-
assert_eq!(v.len(), usize::max_value() - 1);
577+
for _ in v.drain(usize::MAX - 1..=usize::MAX - 1) {}
578+
assert_eq!(v.len(), usize::MAX - 1);
579579
}
580580

581581
#[test]

src/libcore/cell.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,16 +1097,16 @@ impl<'b> BorrowRef<'b> {
10971097
// Incrementing borrow can result in a non-reading value (<= 0) in these cases:
10981098
// 1. It was < 0, i.e. there are writing borrows, so we can't allow a read borrow
10991099
// due to Rust's reference aliasing rules
1100-
// 2. It was isize::max_value() (the max amount of reading borrows) and it overflowed
1101-
// into isize::min_value() (the max amount of writing borrows) so we can't allow
1100+
// 2. It was isize::MAX (the max amount of reading borrows) and it overflowed
1101+
// into isize::MIN (the max amount of writing borrows) so we can't allow
11021102
// an additional read borrow because isize can't represent so many read borrows
11031103
// (this can only happen if you mem::forget more than a small constant amount of
11041104
// `Ref`s, which is not good practice)
11051105
None
11061106
} else {
11071107
// Incrementing borrow can result in a reading value (> 0) in these cases:
11081108
// 1. It was = 0, i.e. it wasn't borrowed, and we are taking the first read borrow
1109-
// 2. It was > 0 and < isize::max_value(), i.e. there were read borrows, and isize
1109+
// 2. It was > 0 and < isize::MAX, i.e. there were read borrows, and isize
11101110
// is large enough to represent having one more read borrow
11111111
borrow.set(b);
11121112
Some(BorrowRef { borrow })
@@ -1132,7 +1132,7 @@ impl Clone for BorrowRef<'_> {
11321132
debug_assert!(is_reading(borrow));
11331133
// Prevent the borrow counter from overflowing into
11341134
// a writing borrow.
1135-
assert!(borrow != isize::max_value());
1135+
assert!(borrow != isize::MAX);
11361136
self.borrow.set(borrow + 1);
11371137
BorrowRef { borrow: self.borrow }
11381138
}
@@ -1356,7 +1356,7 @@ impl<'b> BorrowRefMut<'b> {
13561356
let borrow = self.borrow.get();
13571357
debug_assert!(is_writing(borrow));
13581358
// Prevent the borrow counter from underflowing.
1359-
assert!(borrow != isize::min_value());
1359+
assert!(borrow != isize::MIN);
13601360
self.borrow.set(borrow - 1);
13611361
BorrowRefMut { borrow: self.borrow }
13621362
}

src/libcore/convert/num.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ macro_rules! try_from_upper_bounded {
217217
/// is outside of the range of the target type.
218218
#[inline]
219219
fn try_from(u: $source) -> Result<Self, Self::Error> {
220-
if u > (Self::max_value() as $source) {
220+
if u > (Self::MAX as $source) {
221221
Err(TryFromIntError(()))
222222
} else {
223223
Ok(u as Self)
@@ -239,8 +239,8 @@ macro_rules! try_from_both_bounded {
239239
/// is outside of the range of the target type.
240240
#[inline]
241241
fn try_from(u: $source) -> Result<Self, Self::Error> {
242-
let min = Self::min_value() as $source;
243-
let max = Self::max_value() as $source;
242+
let min = Self::MIN as $source;
243+
let max = Self::MAX as $source;
244244
if u < min || u > max {
245245
Err(TryFromIntError(()))
246246
} else {

src/libcore/intrinsics.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,14 +1300,14 @@ extern "rust-intrinsic" {
13001300
pub fn mul_with_overflow<T>(x: T, y: T) -> (T, bool);
13011301

13021302
/// Performs an exact division, resulting in undefined behavior where
1303-
/// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`
1303+
/// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
13041304
pub fn exact_div<T>(x: T, y: T) -> T;
13051305

13061306
/// Performs an unchecked division, resulting in undefined behavior
1307-
/// where y = 0 or x = `T::min_value()` and y = -1
1307+
/// where y = 0 or x = `T::MIN` and y = -1
13081308
pub fn unchecked_div<T>(x: T, y: T) -> T;
13091309
/// Returns the remainder of an unchecked division, resulting in
1310-
/// undefined behavior where y = 0 or x = `T::min_value()` and y = -1
1310+
/// undefined behavior where y = 0 or x = `T::MIN` and y = -1
13111311
pub fn unchecked_rem<T>(x: T, y: T) -> T;
13121312

13131313
/// Performs an unchecked left shift, resulting in undefined behavior when
@@ -1320,15 +1320,15 @@ extern "rust-intrinsic" {
13201320
pub fn unchecked_shr<T>(x: T, y: T) -> T;
13211321

13221322
/// Returns the result of an unchecked addition, resulting in
1323-
/// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`.
1323+
/// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.
13241324
pub fn unchecked_add<T>(x: T, y: T) -> T;
13251325

13261326
/// Returns the result of an unchecked subtraction, resulting in
1327-
/// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`.
1327+
/// undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`.
13281328
pub fn unchecked_sub<T>(x: T, y: T) -> T;
13291329

13301330
/// Returns the result of an unchecked multiplication, resulting in
1331-
/// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`.
1331+
/// undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`.
13321332
pub fn unchecked_mul<T>(x: T, y: T) -> T;
13331333

13341334
/// Performs rotate left.

src/libcore/iter/traits/iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub trait Iterator {
195195
/// // and the maximum possible lower bound
196196
/// let iter = 0..;
197197
///
198-
/// assert_eq!((usize::max_value(), None), iter.size_hint());
198+
/// assert_eq!((usize::MAX, None), iter.size_hint());
199199
/// ```
200200
#[inline]
201201
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/num/int_macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ macro_rules! int_module {
66
/// The smallest value that can be represented by this integer type.
77
#[$attr]
88
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant MIN")]
9-
pub const MIN: $T = $T::min_value();
9+
pub const MIN: $T = $T::MIN;
1010
/// The largest value that can be represented by this integer type.
1111
#[$attr]
1212
#[rustc_deprecated(since = "1.42.0", reason = "replaced by associated constant MAX")]
13-
pub const MAX: $T = $T::max_value();
13+
pub const MAX: $T = $T::MAX;
1414
)
1515
}

0 commit comments

Comments
 (0)