Skip to content

Commit

Permalink
Replace deprecated items
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed Jun 2, 2020
1 parent 83b75db commit 9e81b51
Show file tree
Hide file tree
Showing 107 changed files with 609 additions and 703 deletions.
4 changes: 2 additions & 2 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@ trait RcBoxPtr<T: ?Sized> {
// The reference count will never be zero when this is called;
// nevertheless, we insert an abort here to hint LLVM at
// an otherwise missed optimization.
if strong == 0 || strong == usize::max_value() {
if strong == 0 || strong == usize::MAX {
// remove `unsafe` on bootstrap bump
#[cfg_attr(not(bootstrap), allow(unused_unsafe))]
unsafe {
Expand Down Expand Up @@ -2062,7 +2062,7 @@ trait RcBoxPtr<T: ?Sized> {
// The reference count will never be zero when this is called;
// nevertheless, we insert an abort here to hint LLVM at
// an otherwise missed optimization.
if weak == 0 || weak == usize::max_value() {
if weak == 0 || weak == usize::MAX {
// remove `unsafe` on bootstrap bump
#[cfg_attr(not(bootstrap), allow(unused_unsafe))]
unsafe {
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/rc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,14 @@ fn test_from_vec() {
fn test_downcast() {
use std::any::Any;

let r1: Rc<dyn Any> = Rc::new(i32::max_value());
let r1: Rc<dyn Any> = Rc::new(i32::MAX);
let r2: Rc<dyn Any> = Rc::new("abc");

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

let r1i32 = r1.downcast::<i32>();
assert!(r1i32.is_ok());
assert_eq!(r1i32.unwrap(), Rc::new(i32::max_value()));
assert_eq!(r1i32.unwrap(), Rc::new(i32::MAX));

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

Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/sync/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,14 @@ fn test_from_vec() {
fn test_downcast() {
use std::any::Any;

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

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

let r1i32 = r1.downcast::<i32>();
assert!(r1i32.is_ok());
assert_eq!(r1i32.unwrap(), Arc::new(i32::max_value()));
assert_eq!(r1i32.unwrap(), Arc::new(i32::MAX));

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

Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/tests/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,13 @@ mod slice_index {
data: "hello";
// note: using 0 specifically ensures that the result of overflowing is 0..0,
// so that `get` doesn't simply return None for the wrong reason.
bad: data[0..=usize::max_value()];
bad: data[0..=usize::MAX];
message: "maximum usize";
}

in mod rangetoinclusive {
data: "hello";
bad: data[..=usize::max_value()];
bad: data[..=usize::MAX];
message: "maximum usize";
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/liballoc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn test_reserve() {

#[test]
fn test_zst_capacity() {
assert_eq!(Vec::<()>::new().capacity(), usize::max_value());
assert_eq!(Vec::<()>::new().capacity(), usize::MAX);
}

#[test]
Expand Down Expand Up @@ -563,19 +563,19 @@ fn test_drain_inclusive_range() {

#[test]
fn test_drain_max_vec_size() {
let mut v = Vec::<()>::with_capacity(usize::max_value());
let mut v = Vec::<()>::with_capacity(usize::MAX);
unsafe {
v.set_len(usize::max_value());
v.set_len(usize::MAX);
}
for _ in v.drain(usize::max_value() - 1..) {}
assert_eq!(v.len(), usize::max_value() - 1);
for _ in v.drain(usize::MAX - 1..) {}
assert_eq!(v.len(), usize::MAX - 1);

let mut v = Vec::<()>::with_capacity(usize::max_value());
let mut v = Vec::<()>::with_capacity(usize::MAX);
unsafe {
v.set_len(usize::max_value());
v.set_len(usize::MAX);
}
for _ in v.drain(usize::max_value() - 1..=usize::max_value() - 1) {}
assert_eq!(v.len(), usize::max_value() - 1);
for _ in v.drain(usize::MAX - 1..=usize::MAX - 1) {}
assert_eq!(v.len(), usize::MAX - 1);
}

#[test]
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,16 +1163,16 @@ impl<'b> BorrowRef<'b> {
// Incrementing borrow can result in a non-reading value (<= 0) in these cases:
// 1. It was < 0, i.e. there are writing borrows, so we can't allow a read borrow
// due to Rust's reference aliasing rules
// 2. It was isize::max_value() (the max amount of reading borrows) and it overflowed
// into isize::min_value() (the max amount of writing borrows) so we can't allow
// 2. It was isize::MAX (the max amount of reading borrows) and it overflowed
// into isize::MIN (the max amount of writing borrows) so we can't allow
// an additional read borrow because isize can't represent so many read borrows
// (this can only happen if you mem::forget more than a small constant amount of
// `Ref`s, which is not good practice)
None
} else {
// Incrementing borrow can result in a reading value (> 0) in these cases:
// 1. It was = 0, i.e. it wasn't borrowed, and we are taking the first read borrow
// 2. It was > 0 and < isize::max_value(), i.e. there were read borrows, and isize
// 2. It was > 0 and < isize::MAX, i.e. there were read borrows, and isize
// is large enough to represent having one more read borrow
borrow.set(b);
Some(BorrowRef { borrow })
Expand All @@ -1198,7 +1198,7 @@ impl Clone for BorrowRef<'_> {
debug_assert!(is_reading(borrow));
// Prevent the borrow counter from overflowing into
// a writing borrow.
assert!(borrow != isize::max_value());
assert!(borrow != isize::MAX);
self.borrow.set(borrow + 1);
BorrowRef { borrow: self.borrow }
}
Expand Down Expand Up @@ -1489,7 +1489,7 @@ impl<'b> BorrowRefMut<'b> {
let borrow = self.borrow.get();
debug_assert!(is_writing(borrow));
// Prevent the borrow counter from underflowing.
assert!(borrow != isize::min_value());
assert!(borrow != isize::MIN);
self.borrow.set(borrow - 1);
BorrowRefMut { borrow: self.borrow }
}
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/convert/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ macro_rules! try_from_upper_bounded {
/// is outside of the range of the target type.
#[inline]
fn try_from(u: $source) -> Result<Self, Self::Error> {
if u > (Self::max_value() as $source) {
if u > (Self::MAX as $source) {
Err(TryFromIntError(()))
} else {
Ok(u as Self)
Expand All @@ -239,8 +239,8 @@ macro_rules! try_from_both_bounded {
/// is outside of the range of the target type.
#[inline]
fn try_from(u: $source) -> Result<Self, Self::Error> {
let min = Self::min_value() as $source;
let max = Self::max_value() as $source;
let min = Self::MIN as $source;
let max = Self::MAX as $source;
if u < min || u > max {
Err(TryFromIntError(()))
} else {
Expand Down
28 changes: 14 additions & 14 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ use crate::num::FpCategory;
#[rustc_deprecated(
since = "1.46.0",
reason = "The associated constant `f32::RADIX` is now prefered",
suggestion = "f32::RADIX",
suggestion = "f32::RADIX"
)]
pub const RADIX: u32 = f32::RADIX;

/// Number of significant digits in base 2.
#[rustc_deprecated(
since = "1.46.0",
reason = "The associated constant `f32::MANTISSA_DIGITS` is now prefered",
suggestion = "f32::MANTISSA_DIGITS",
suggestion = "f32::MANTISSA_DIGITS"
)]
#[stable(feature = "rust1", since = "1.0.0")]
pub const MANTISSA_DIGITS: u32 = f32::MANTISSA_DIGITS;
Expand All @@ -36,7 +36,7 @@ pub const MANTISSA_DIGITS: u32 = f32::MANTISSA_DIGITS;
#[rustc_deprecated(
since = "1.46.0",
reason = "The associated constant `f32::DIGITS` is now prefered",
suggestion = "f32::DIGITS",
suggestion = "f32::DIGITS"
)]
pub const DIGITS: u32 = f32::DIGITS;

Expand All @@ -47,7 +47,7 @@ pub const DIGITS: u32 = f32::DIGITS;
#[rustc_deprecated(
since = "1.46.0",
reason = "The associated constant `f32::EPSILON` is now prefered",
suggestion = "f32::EPSILON",
suggestion = "f32::EPSILON"
)]
pub const EPSILON: f32 = f32::EPSILON;

Expand All @@ -56,7 +56,7 @@ pub const EPSILON: f32 = f32::EPSILON;
#[rustc_deprecated(
since = "1.46.0",
reason = "The associated constant `f32::MIN` is now prefered",
suggestion = "f32::MIN",
suggestion = "f32::MIN"
)]
pub const MIN: f32 = f32::MIN;

Expand All @@ -65,7 +65,7 @@ pub const MIN: f32 = f32::MIN;
#[rustc_deprecated(
since = "1.46.0",
reason = "The associated constant `f32::MIN_POSITIVE` is now prefered",
suggestion = "f32::MIN_POSITIVE",
suggestion = "f32::MIN_POSITIVE"
)]
pub const MIN_POSITIVE: f32 = f32::MIN_POSITIVE;

Expand All @@ -74,7 +74,7 @@ pub const MIN_POSITIVE: f32 = f32::MIN_POSITIVE;
#[rustc_deprecated(
since = "1.46.0",
reason = "The associated constant `f32::MAX` is now prefered",
suggestion = "f32::MAX",
suggestion = "f32::MAX"
)]
pub const MAX: f32 = f32::MAX;

Expand All @@ -83,7 +83,7 @@ pub const MAX: f32 = f32::MAX;
#[rustc_deprecated(
since = "1.46.0",
reason = "The associated constant `f32::MIN_EXP` is now prefered",
suggestion = "f32::MIN_EXP",
suggestion = "f32::MIN_EXP"
)]
pub const MIN_EXP: i32 = f32::MIN_EXP;

Expand All @@ -92,7 +92,7 @@ pub const MIN_EXP: i32 = f32::MIN_EXP;
#[rustc_deprecated(
since = "1.46.0",
reason = "The associated constant `f32::MAX_EXP` is now prefered",
suggestion = "f32::MAX_EXP",
suggestion = "f32::MAX_EXP"
)]
pub const MAX_EXP: i32 = f32::MAX_EXP;

Expand All @@ -101,7 +101,7 @@ pub const MAX_EXP: i32 = f32::MAX_EXP;
#[rustc_deprecated(
since = "1.46.0",
reason = "The associated constant `f32::MIN_10_EXP` is now prefered",
suggestion = "f32::MIN_10_EXP",
suggestion = "f32::MIN_10_EXP"
)]
pub const MIN_10_EXP: i32 = f32::MIN_10_EXP;

Expand All @@ -110,7 +110,7 @@ pub const MIN_10_EXP: i32 = f32::MIN_10_EXP;
#[rustc_deprecated(
since = "1.46.0",
reason = "The associated constant `f32::MAX_10_EXP` is now prefered",
suggestion = "f32::MAX_10_EXP",
suggestion = "f32::MAX_10_EXP"
)]
pub const MAX_10_EXP: i32 = f32::MAX_10_EXP;

Expand All @@ -119,7 +119,7 @@ pub const MAX_10_EXP: i32 = f32::MAX_10_EXP;
#[rustc_deprecated(
since = "1.46.0",
reason = "The associated constant `f32::NAN` is now prefered",
suggestion = "f32::NAN",
suggestion = "f32::NAN"
)]
pub const NAN: f32 = f32::NAN;

Expand All @@ -128,7 +128,7 @@ pub const NAN: f32 = f32::NAN;
#[rustc_deprecated(
since = "1.46.0",
reason = "The associated constant `f32::INFINITY` is now prefered",
suggestion = "f32::INFINITY",
suggestion = "f32::INFINITY"
)]
pub const INFINITY: f32 = f32::INFINITY;

Expand All @@ -137,7 +137,7 @@ pub const INFINITY: f32 = f32::INFINITY;
#[rustc_deprecated(
since = "1.46.0",
reason = "The associated constant `f32::NEG_INFINITY` is now prefered",
suggestion = "f32::NEG_INFINITY",
suggestion = "f32::NEG_INFINITY"
)]
pub const NEG_INFINITY: f32 = f32::NEG_INFINITY;

Expand Down
Loading

0 comments on commit 9e81b51

Please sign in to comment.