diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 4edbc2ff3ac9b..012e0e4c66ca1 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -2034,7 +2034,7 @@ trait RcBoxPtr { // 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 { @@ -2062,7 +2062,7 @@ trait RcBoxPtr { // 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 { diff --git a/src/liballoc/rc/tests.rs b/src/liballoc/rc/tests.rs index 56788bb56d550..e88385faf4fd4 100644 --- a/src/liballoc/rc/tests.rs +++ b/src/liballoc/rc/tests.rs @@ -407,14 +407,14 @@ fn test_from_vec() { fn test_downcast() { use std::any::Any; - let r1: Rc = Rc::new(i32::max_value()); + let r1: Rc = Rc::new(i32::MAX); let r2: Rc = Rc::new("abc"); assert!(r1.clone().downcast::().is_err()); let r1i32 = r1.downcast::(); 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::().is_err()); diff --git a/src/liballoc/sync/tests.rs b/src/liballoc/sync/tests.rs index a2bb651e2b778..6f08cd7f123be 100644 --- a/src/liballoc/sync/tests.rs +++ b/src/liballoc/sync/tests.rs @@ -465,14 +465,14 @@ fn test_from_vec() { fn test_downcast() { use std::any::Any; - let r1: Arc = Arc::new(i32::max_value()); + let r1: Arc = Arc::new(i32::MAX); let r2: Arc = Arc::new("abc"); assert!(r1.clone().downcast::().is_err()); let r1i32 = r1.downcast::(); 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::().is_err()); diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs index b703df6f3cb7d..eee98d4534042 100644 --- a/src/liballoc/tests/str.rs +++ b/src/liballoc/tests/str.rs @@ -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"; } } diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs index b16044d964045..edf863272680c 100644 --- a/src/liballoc/tests/vec.rs +++ b/src/liballoc/tests/vec.rs @@ -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] @@ -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] diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index c4c1d2824b098..cadc2e631b0fa 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -1163,8 +1163,8 @@ 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) @@ -1172,7 +1172,7 @@ impl<'b> BorrowRef<'b> { } 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 }) @@ -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 } } @@ -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 } } diff --git a/src/libcore/convert/num.rs b/src/libcore/convert/num.rs index 6dd0522f7f610..5ff52a9a11b5a 100644 --- a/src/libcore/convert/num.rs +++ b/src/libcore/convert/num.rs @@ -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 { - if u > (Self::max_value() as $source) { + if u > (Self::MAX as $source) { Err(TryFromIntError(())) } else { Ok(u as Self) @@ -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 { - 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 { diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index 6313de31ce4d5..3ed10494d83a2 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -4,9 +4,6 @@ //! *[See also the `f32` primitive type](../../std/primitive.f32.html).* //! //! Mathematically significant numbers are provided in the `consts` sub-module. -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "rust1", since = "1.0.0")] @@ -17,217 +14,131 @@ use crate::mem; use crate::num::FpCategory; /// The radix or base of the internal representation of `f32`. -/// Use [`f32::RADIX`](../../std/primitive.f32.html#associatedconstant.RADIX) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let r = std::f32::RADIX; -/// -/// // intended way -/// let r = f32::RADIX; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f32::RADIX` is now prefered", + suggestion = "f32::RADIX" +)] pub const RADIX: u32 = f32::RADIX; /// Number of significant digits in base 2. -/// Use [`f32::MANTISSA_DIGITS`](../../std/primitive.f32.html#associatedconstant.MANTISSA_DIGITS) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let d = std::f32::MANTISSA_DIGITS; -/// -/// // intended way -/// let d = f32::MANTISSA_DIGITS; -/// ``` +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f32::MANTISSA_DIGITS` is now prefered", + suggestion = "f32::MANTISSA_DIGITS" +)] #[stable(feature = "rust1", since = "1.0.0")] pub const MANTISSA_DIGITS: u32 = f32::MANTISSA_DIGITS; /// Approximate number of significant digits in base 10. -/// Use [`f32::DIGITS`](../../std/primitive.f32.html#associatedconstant.DIGITS) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let d = std::f32::DIGITS; -/// -/// // intended way -/// let d = f32::DIGITS; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f32::DIGITS` is now prefered", + suggestion = "f32::DIGITS" +)] pub const DIGITS: u32 = f32::DIGITS; /// [Machine epsilon] value for `f32`. -/// Use [`f32::EPSILON`](../../std/primitive.f32.html#associatedconstant.EPSILON) instead. -/// -/// This is the difference between `1.0` and the next larger representable number. /// /// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let e = std::f32::EPSILON; -/// -/// // intended way -/// let e = f32::EPSILON; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f32::EPSILON` is now prefered", + suggestion = "f32::EPSILON" +)] pub const EPSILON: f32 = f32::EPSILON; /// Smallest finite `f32` value. -/// Use [`f32::MIN`](../../std/primitive.f32.html#associatedconstant.MIN) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let min = std::f32::MIN; -/// -/// // intended way -/// let min = f32::MIN; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f32::MIN` is now prefered", + suggestion = "f32::MIN" +)] pub const MIN: f32 = f32::MIN; /// Smallest positive normal `f32` value. -/// Use [`f32::MIN_POSITIVE`](../../std/primitive.f32.html#associatedconstant.MIN_POSITIVE) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let min = std::f32::MIN_POSITIVE; -/// -/// // intended way -/// let min = f32::MIN_POSITIVE; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f32::MIN_POSITIVE` is now prefered", + suggestion = "f32::MIN_POSITIVE" +)] pub const MIN_POSITIVE: f32 = f32::MIN_POSITIVE; /// Largest finite `f32` value. -/// Use [`f32::MAX`](../../std/primitive.f32.html#associatedconstant.MAX) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let max = std::f32::MAX; -/// -/// // intended way -/// let max = f32::MAX; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f32::MAX` is now prefered", + suggestion = "f32::MAX" +)] pub const MAX: f32 = f32::MAX; /// One greater than the minimum possible normal power of 2 exponent. -/// Use [`f32::MIN_EXP`](../../std/primitive.f32.html#associatedconstant.MIN_EXP) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let min = std::f32::MIN_EXP; -/// -/// // intended way -/// let min = f32::MIN_EXP; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f32::MIN_EXP` is now prefered", + suggestion = "f32::MIN_EXP" +)] pub const MIN_EXP: i32 = f32::MIN_EXP; /// Maximum possible power of 2 exponent. -/// Use [`f32::MAX_EXP`](../../std/primitive.f32.html#associatedconstant.MAX_EXP) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let max = std::f32::MAX_EXP; -/// -/// // intended way -/// let max = f32::MAX_EXP; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f32::MAX_EXP` is now prefered", + suggestion = "f32::MAX_EXP" +)] pub const MAX_EXP: i32 = f32::MAX_EXP; /// Minimum possible normal power of 10 exponent. -/// Use [`f32::MIN_10_EXP`](../../std/primitive.f32.html#associatedconstant.MIN_10_EXP) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let min = std::f32::MIN_10_EXP; -/// -/// // intended way -/// let min = f32::MIN_10_EXP; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f32::MIN_10_EXP` is now prefered", + suggestion = "f32::MIN_10_EXP" +)] pub const MIN_10_EXP: i32 = f32::MIN_10_EXP; /// Maximum possible power of 10 exponent. -/// Use [`f32::MAX_10_EXP`](../../std/primitive.f32.html#associatedconstant.MAX_10_EXP) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let max = std::f32::MAX_10_EXP; -/// -/// // intended way -/// let max = f32::MAX_10_EXP; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f32::MAX_10_EXP` is now prefered", + suggestion = "f32::MAX_10_EXP" +)] pub const MAX_10_EXP: i32 = f32::MAX_10_EXP; /// Not a Number (NaN). -/// Use [`f32::NAN`](../../std/primitive.f32.html#associatedconstant.NAN) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let nan = std::f32::NAN; -/// -/// // intended way -/// let nan = f32::NAN; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f32::NAN` is now prefered", + suggestion = "f32::NAN" +)] pub const NAN: f32 = f32::NAN; /// Infinity (∞). -/// Use [`f32::INFINITY`](../../std/primitive.f32.html#associatedconstant.INFINITY) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let inf = std::f32::INFINITY; -/// -/// // intended way -/// let inf = f32::INFINITY; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f32::INFINITY` is now prefered", + suggestion = "f32::INFINITY" +)] pub const INFINITY: f32 = f32::INFINITY; /// Negative infinity (−∞). -/// Use [`f32::NEG_INFINITY`](../../std/primitive.f32.html#associatedconstant.NEG_INFINITY) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let ninf = std::f32::NEG_INFINITY; -/// -/// // intended way -/// let ninf = f32::NEG_INFINITY; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f32::NEG_INFINITY` is now prefered", + suggestion = "f32::NEG_INFINITY" +)] pub const NEG_INFINITY: f32 = f32::NEG_INFINITY; /// Basic mathematical constants. diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index d42e5392c5863..b4ce0f5d764b2 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -4,9 +4,6 @@ //! *[See also the `f64` primitive type](../../std/primitive.f64.html).* //! //! Mathematically significant numbers are provided in the `consts` sub-module. -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "rust1", since = "1.0.0")] @@ -17,217 +14,131 @@ use crate::mem; use crate::num::FpCategory; /// The radix or base of the internal representation of `f64`. -/// Use [`f64::RADIX`](../../std/primitive.f64.html#associatedconstant.RADIX) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let r = std::f64::RADIX; -/// -/// // intended way -/// let r = f64::RADIX; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f64::RADIX` is now prefered", + suggestion = "f64::RADIX" +)] pub const RADIX: u32 = f64::RADIX; /// Number of significant digits in base 2. -/// Use [`f64::MANTISSA_DIGITS`](../../std/primitive.f64.html#associatedconstant.MANTISSA_DIGITS) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let d = std::f64::MANTISSA_DIGITS; -/// -/// // intended way -/// let d = f64::MANTISSA_DIGITS; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f64::MANTISSA_DIGITS` is now prefered", + suggestion = "f64::MANTISSA_DIGITS" +)] pub const MANTISSA_DIGITS: u32 = f64::MANTISSA_DIGITS; /// Approximate number of significant digits in base 10. -/// Use [`f64::DIGITS`](../../std/primitive.f64.html#associatedconstant.DIGITS) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let d = std::f64::DIGITS; -/// -/// // intended way -/// let d = f64::DIGITS; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f64::DIGITS` is now prefered", + suggestion = "f64::DIGITS" +)] pub const DIGITS: u32 = f64::DIGITS; /// [Machine epsilon] value for `f64`. -/// Use [`f64::EPSILON`](../../std/primitive.f64.html#associatedconstant.EPSILON) instead. -/// -/// This is the difference between `1.0` and the next larger representable number. /// /// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let e = std::f64::EPSILON; -/// -/// // intended way -/// let e = f64::EPSILON; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f64::EPSILON` is now prefered", + suggestion = "f64::EPSILON" +)] pub const EPSILON: f64 = f64::EPSILON; /// Smallest finite `f64` value. -/// Use [`f64::MIN`](../../std/primitive.f64.html#associatedconstant.MIN) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let min = std::f64::MIN; -/// -/// // intended way -/// let min = f64::MIN; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f64::MIN` is now prefered", + suggestion = "f64::MIN" +)] pub const MIN: f64 = f64::MIN; /// Smallest positive normal `f64` value. -/// Use [`f64::MIN_POSITIVE`](../../std/primitive.f64.html#associatedconstant.MIN_POSITIVE) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let min = std::f64::MIN_POSITIVE; -/// -/// // intended way -/// let min = f64::MIN_POSITIVE; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f64::MIN_POSITIVE` is now prefered", + suggestion = "f64::MIN_POSITIVE" +)] pub const MIN_POSITIVE: f64 = f64::MIN_POSITIVE; /// Largest finite `f64` value. -/// Use [`f64::MAX`](../../std/primitive.f64.html#associatedconstant.MAX) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let max = std::f64::MAX; -/// -/// // intended way -/// let max = f64::MAX; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f64::MAX` is now prefered", + suggestion = "f64::MAX" +)] pub const MAX: f64 = f64::MAX; /// One greater than the minimum possible normal power of 2 exponent. -/// Use [`f64::MIN_EXP`](../../std/primitive.f64.html#associatedconstant.MIN_EXP) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let min = std::f64::MIN_EXP; -/// -/// // intended way -/// let min = f64::MIN_EXP; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f64::MIN_EXP` is now prefered", + suggestion = "f64::MIN_EXP" +)] pub const MIN_EXP: i32 = f64::MIN_EXP; /// Maximum possible power of 2 exponent. -/// Use [`f64::MAX_EXP`](../../std/primitive.f64.html#associatedconstant.MAX_EXP) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let max = std::f64::MAX_EXP; -/// -/// // intended way -/// let max = f64::MAX_EXP; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f64::MAX_EXP` is now prefered", + suggestion = "f64::MAX_EXP" +)] pub const MAX_EXP: i32 = f64::MAX_EXP; /// Minimum possible normal power of 10 exponent. -/// Use [`f64::MIN_10_EXP`](../../std/primitive.f64.html#associatedconstant.MIN_10_EXP) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let min = std::f64::MIN_10_EXP; -/// -/// // intended way -/// let min = f64::MIN_10_EXP; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f64::MIN_10_EXP` is now prefered", + suggestion = "f64::MIN_10_EXP" +)] pub const MIN_10_EXP: i32 = f64::MIN_10_EXP; /// Maximum possible power of 10 exponent. -/// Use [`f64::MAX_10_EXP`](../../std/primitive.f64.html#associatedconstant.MAX_10_EXP) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let max = std::f64::MAX_10_EXP; -/// -/// // intended way -/// let max = f64::MAX_10_EXP; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f64::MAX_10_EXP` is now prefered", + suggestion = "f64::MAX_10_EXP" +)] pub const MAX_10_EXP: i32 = f64::MAX_10_EXP; /// Not a Number (NaN). -/// Use [`f64::NAN`](../../std/primitive.f64.html#associatedconstant.NAN) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let nan = std::f64::NAN; -/// -/// // intended way -/// let nan = f64::NAN; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f64::NAN` is now prefered", + suggestion = "f64::NAN" +)] pub const NAN: f64 = f64::NAN; /// Infinity (∞). -/// Use [`f64::INFINITY`](../../std/primitive.f64.html#associatedconstant.INFINITY) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let inf = std::f64::INFINITY; -/// -/// // intended way -/// let inf = f64::INFINITY; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f64::INFINITY` is now prefered", + suggestion = "f64::INFINITY" +)] pub const INFINITY: f64 = f64::INFINITY; /// Negative infinity (−∞). -/// Use [`f64::NEG_INFINITY`](../../std/primitive.f64.html#associatedconstant.NEG_INFINITY) instead. -/// -/// # Examples -/// -/// ```rust -/// // deprecated way -/// let ninf = std::f64::NEG_INFINITY; -/// -/// // intended way -/// let ninf = f64::NEG_INFINITY; -/// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant `f64::NEG_INFINITY` is now prefered", + suggestion = "f64::NEG_INFINITY" +)] pub const NEG_INFINITY: f64 = f64::NEG_INFINITY; /// Basic mathematical constants. diff --git a/src/libcore/num/i128.rs b/src/libcore/num/i128.rs index 08cb795946868..564ed598a882c 100644 --- a/src/libcore/num/i128.rs +++ b/src/libcore/num/i128.rs @@ -1,9 +1,6 @@ //! The 128-bit signed integer type. //! //! *[See also the `i128` primitive type](../../std/primitive.i128.html).* -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "i128", since = "1.26.0")] diff --git a/src/libcore/num/i16.rs b/src/libcore/num/i16.rs index 288eaceba59d6..44d6aaef25ba0 100644 --- a/src/libcore/num/i16.rs +++ b/src/libcore/num/i16.rs @@ -1,9 +1,6 @@ //! The 16-bit signed integer type. //! //! *[See also the `i16` primitive type](../../std/primitive.i16.html).* -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/i32.rs b/src/libcore/num/i32.rs index 0e1a2ec56ccb2..90a5f89195e31 100644 --- a/src/libcore/num/i32.rs +++ b/src/libcore/num/i32.rs @@ -1,9 +1,6 @@ //! The 32-bit signed integer type. //! //! *[See also the `i32` primitive type](../../std/primitive.i32.html).* -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/i64.rs b/src/libcore/num/i64.rs index 27f7092710b34..04a8a9d757915 100644 --- a/src/libcore/num/i64.rs +++ b/src/libcore/num/i64.rs @@ -1,9 +1,6 @@ //! The 64-bit signed integer type. //! //! *[See also the `i64` primitive type](../../std/primitive.i64.html).* -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/i8.rs b/src/libcore/num/i8.rs index e84b421e1a444..5a52a967cf96d 100644 --- a/src/libcore/num/i8.rs +++ b/src/libcore/num/i8.rs @@ -1,9 +1,6 @@ //! The 8-bit signed integer type. //! //! *[See also the `i8` primitive type](../../std/primitive.i8.html).* -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/int_macros.rs b/src/libcore/num/int_macros.rs index ffd30b03f2109..323482f3054d9 100644 --- a/src/libcore/num/int_macros.rs +++ b/src/libcore/num/int_macros.rs @@ -1,49 +1,22 @@ #![doc(hidden)] -macro_rules! doc_comment { - ($x:expr, $($tt:tt)*) => { - #[doc = $x] - $($tt)* - }; -} - macro_rules! int_module { ($T:ident) => (int_module!($T, #[stable(feature = "rust1", since = "1.0.0")]);); ($T:ident, #[$attr:meta]) => ( - doc_comment! { - concat!("The smallest value that can be represented by this integer type. -Use [`", stringify!($T), "::MIN", "`](../../std/primitive.", stringify!($T), ".html#associatedconstant.MIN) instead. - -# Examples - -```rust -// deprecated way -let min = std::", stringify!($T), "::MIN; - -// intended way -let min = ", stringify!($T), "::MIN; -``` -"), - #[$attr] - pub const MIN: $T = $T::MIN; - } - - doc_comment! { - concat!("The largest value that can be represented by this integer type. -Use [`", stringify!($T), "::MAX", "`](../../std/primitive.", stringify!($T), ".html#associatedconstant.MAX) instead. - -# Examples - -```rust -// deprecated way -let max = std::", stringify!($T), "::MAX; - -// intended way -let max = ", stringify!($T), "::MAX; -``` -"), - #[$attr] - pub const MAX: $T = $T::MAX; - } + /// The smallest value that can be represented by this integer type. + #[$attr] + #[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant MIN is now prefered", + )] + pub const MIN: $T = $T::MIN; + + /// The largest value that can be represented by this integer type. + #[$attr] + #[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant MAX is now prefered", + )] + pub const MAX: $T = $T::MAX; ) } diff --git a/src/libcore/num/isize.rs b/src/libcore/num/isize.rs index 0dcfa4a2bd134..143f8b3b272d6 100644 --- a/src/libcore/num/isize.rs +++ b/src/libcore/num/isize.rs @@ -1,9 +1,6 @@ //! The pointer-sized signed integer type. //! //! *[See also the `isize` primitive type](../../std/primitive.isize.html).* -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index c164e893b4fbf..6dcd3c16b56e0 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -749,21 +749,18 @@ $EndFeature, " } } - doc_comment! { - concat!("Unchecked integer addition. Computes `self + rhs, assuming overflow -cannot occur. This results in undefined behavior when `self + rhs > ", stringify!($SelfT), -"::max_value()` or `self + rhs < ", stringify!($SelfT), "::min_value()`."), - #[unstable( - feature = "unchecked_math", - reason = "niche optimization path", - issue = "none", - )] - #[must_use = "this returns the result of the operation, \ - without modifying the original"] - #[inline] - pub unsafe fn unchecked_add(self, rhs: Self) -> Self { - intrinsics::unchecked_add(self, rhs) - } + /// Unchecked integer addition. Computes `self + rhs`, assuming overflow + /// cannot occur. This results in undefined behavior when `self + rhs > Self::MAX` + /// or `self + rhs < Self::MIN`. + #[unstable( + feature = "unchecked_math", + reason = "niche optimization path", + issue = "none", + )] + #[must_use = "this returns the result of the operation, without modifying the original"] + #[inline] + pub unsafe fn unchecked_add(self, rhs: Self) -> Self { + intrinsics::unchecked_add(self, rhs) } doc_comment! { @@ -791,21 +788,18 @@ $EndFeature, " } } - doc_comment! { - concat!("Unchecked integer subtraction. Computes `self - rhs, assuming overflow -cannot occur. This results in undefined behavior when `self - rhs > ", stringify!($SelfT), -"::max_value()` or `self - rhs < ", stringify!($SelfT), "::min_value()`."), - #[unstable( - feature = "unchecked_math", - reason = "niche optimization path", - issue = "none", - )] - #[must_use = "this returns the result of the operation, \ - without modifying the original"] - #[inline] - pub unsafe fn unchecked_sub(self, rhs: Self) -> Self { - intrinsics::unchecked_sub(self, rhs) - } + /// Unchecked integer subtraction. Computes `self - rhs`, assuming overflow + /// cannot occur. This results in undefined behavior when `self - rhs > Self::MAX` + /// or `self - rhs < Self::MIN`. + #[unstable( + feature = "unchecked_math", + reason = "niche optimization path", + issue = "none", + )] + #[must_use = "this returns the result of the operation, without modifying the original"] + #[inline] + pub unsafe fn unchecked_sub(self, rhs: Self) -> Self { + intrinsics::unchecked_sub(self, rhs) } doc_comment! { @@ -833,21 +827,18 @@ $EndFeature, " } } - doc_comment! { - concat!("Unchecked integer multiplication. Computes `self * rhs, assuming overflow -cannot occur. This results in undefined behavior when `self * rhs > ", stringify!($SelfT), -"::max_value()` or `self * rhs < ", stringify!($SelfT), "::min_value()`."), - #[unstable( - feature = "unchecked_math", - reason = "niche optimization path", - issue = "none", - )] - #[must_use = "this returns the result of the operation, \ - without modifying the original"] - #[inline] - pub unsafe fn unchecked_mul(self, rhs: Self) -> Self { - intrinsics::unchecked_mul(self, rhs) - } + /// Unchecked integer multiplication. Computes `self * rhs`, assuming overflow + /// cannot occur. This results in undefined behavior when `self * rhs > Self::MAX` + /// or `self * rhs < Self::MIN`. + #[unstable( + feature = "unchecked_math", + reason = "niche optimization path", + issue = "none", + )] + #[must_use = "this returns the result of the operation, without modifying the original"] + #[inline] + pub unsafe fn unchecked_mul(self, rhs: Self) -> Self { + intrinsics::unchecked_mul(self, rhs) } doc_comment! { @@ -871,7 +862,7 @@ $EndFeature, " without modifying the original"] #[inline] pub const fn checked_div(self, rhs: Self) -> Option { - if rhs == 0 || (self == Self::min_value() && rhs == -1) { + if rhs == 0 || (self == Self::MIN && rhs == -1) { None } else { // SAFETY: div by zero and by INT_MIN have been checked above @@ -900,7 +891,7 @@ assert_eq!((1", stringify!($SelfT), ").checked_div_euclid(0), None); without modifying the original"] #[inline] pub const fn checked_div_euclid(self, rhs: Self) -> Option { - if rhs == 0 || (self == Self::min_value() && rhs == -1) { + if rhs == 0 || (self == Self::MIN && rhs == -1) { None } else { Some(self.div_euclid(rhs)) @@ -929,7 +920,7 @@ $EndFeature, " without modifying the original"] #[inline] pub const fn checked_rem(self, rhs: Self) -> Option { - if rhs == 0 || (self == Self::min_value() && rhs == -1) { + if rhs == 0 || (self == Self::MIN && rhs == -1) { None } else { // SAFETY: div by zero and by INT_MIN have been checked above @@ -957,7 +948,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.checked_rem_euclid(-1), None); without modifying the original"] #[inline] pub const fn checked_rem_euclid(self, rhs: Self) -> Option { - if rhs == 0 || (self == Self::min_value() && rhs == -1) { + if rhs == 0 || (self == Self::MIN && rhs == -1) { None } else { Some(self.rem_euclid(rhs)) @@ -1236,9 +1227,9 @@ $EndFeature, " match self.checked_mul(rhs) { Some(x) => x, None => if (self < 0) == (rhs < 0) { - Self::max_value() + Self::MAX } else { - Self::min_value() + Self::MIN } } } @@ -1267,8 +1258,8 @@ $EndFeature, " pub const fn saturating_pow(self, exp: u32) -> Self { match self.checked_pow(exp) { Some(x) => x, - None if self < 0 && exp % 2 == 1 => Self::min_value(), - None => Self::max_value(), + None if self < 0 && exp % 2 == 1 => Self::MIN, + None => Self::MAX, } } } @@ -1738,7 +1729,7 @@ $EndFeature, " #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) { - if self == Self::min_value() && rhs == -1 { + if self == Self::MIN && rhs == -1 { (self, true) } else { (self / rhs, false) @@ -1771,7 +1762,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_div_euclid(-1), (", stringi #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) { - if self == Self::min_value() && rhs == -1 { + if self == Self::MIN && rhs == -1 { (self, true) } else { (self.div_euclid(rhs), false) @@ -1805,7 +1796,7 @@ $EndFeature, " #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) { - if self == Self::min_value() && rhs == -1 { + if self == Self::MIN && rhs == -1 { (0, true) } else { (self % rhs, false) @@ -1838,7 +1829,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_rem_euclid(-1), (0, true)); without modifying the original"] #[inline] pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) { - if self == Self::min_value() && rhs == -1 { + if self == Self::MIN && rhs == -1 { (0, true) } else { (self.rem_euclid(rhs), false) @@ -1869,8 +1860,8 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_neg(), (", stringify!($Self #[allow(unused_attributes)] #[allow_internal_unstable(const_if_match)] pub const fn overflowing_neg(self) -> (Self, bool) { - if self == Self::min_value() { - (Self::min_value(), true) + if self == Self::MIN { + (Self::MIN, true) } else { (-self, false) } @@ -1952,7 +1943,7 @@ $EndFeature, " #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[inline] pub const fn overflowing_abs(self) -> (Self, bool) { - (self.wrapping_abs(), self == Self::min_value()) + (self.wrapping_abs(), self == Self::MIN) } } @@ -2444,36 +2435,30 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), } } - doc_comment! { - concat!("**This method is soft-deprecated.** - -Although using it won’t cause compilation warning, -new code should use [`", stringify!($SelfT), "::MIN", "`](#associatedconstant.MIN) instead. - -Returns the smallest value that can be represented by this integer type."), - #[stable(feature = "rust1", since = "1.0.0")] - #[inline(always)] - #[rustc_promotable] - #[rustc_const_stable(feature = "const_min_value", since = "1.32.0")] - pub const fn min_value() -> Self { - Self::MIN - } - } - - doc_comment! { - concat!("**This method is soft-deprecated.** - -Although using it won’t cause compilation warning, -new code should use [`", stringify!($SelfT), "::MAX", "`](#associatedconstant.MAX) instead. - -Returns the largest value that can be represented by this integer type."), - #[stable(feature = "rust1", since = "1.0.0")] - #[inline(always)] - #[rustc_promotable] - #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")] - pub const fn max_value() -> Self { - Self::MAX - } + /// Returns the smallest value that can be represented by this integer type. + #[stable(feature = "rust1", since = "1.0.0")] + #[inline(always)] + #[rustc_promotable] + #[rustc_const_stable(feature = "const_min_value", since = "1.32.0")] + #[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant MIN is now prefered", + )] + pub const fn min_value() -> Self { + Self::MIN + } + + /// Returns the largest value that can be represented by this integer type. + #[stable(feature = "rust1", since = "1.0.0")] + #[inline(always)] + #[rustc_promotable] + #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")] + #[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant MAX is now prefered", + )] + pub const fn max_value() -> Self { + Self::MAX } } } @@ -2985,21 +2970,18 @@ assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);", $EndFeat } } - doc_comment! { - concat!("Unchecked integer addition. Computes `self + rhs, assuming overflow -cannot occur. This results in undefined behavior when `self + rhs > ", stringify!($SelfT), -"::max_value()` or `self + rhs < ", stringify!($SelfT), "::min_value()`."), - #[unstable( - feature = "unchecked_math", - reason = "niche optimization path", - issue = "none", - )] - #[must_use = "this returns the result of the operation, \ - without modifying the original"] - #[inline] - pub unsafe fn unchecked_add(self, rhs: Self) -> Self { - intrinsics::unchecked_add(self, rhs) - } + /// Unchecked integer addition. Computes `self + rhs`, assuming overflow + /// cannot occur. This results in undefined behavior when `self + rhs > Self::MAX` + /// or `self + rhs < Self::MIN`", + #[unstable( + feature = "unchecked_math", + reason = "niche optimization path", + issue = "none", + )] + #[must_use = "this returns the result of the operation, without modifying the original"] + #[inline] + pub unsafe fn unchecked_add(self, rhs: Self) -> Self { + intrinsics::unchecked_add(self, rhs) } doc_comment! { @@ -3025,21 +3007,18 @@ assert_eq!(0", stringify!($SelfT), ".checked_sub(1), None);", $EndFeature, " } } - doc_comment! { - concat!("Unchecked integer subtraction. Computes `self - rhs, assuming overflow -cannot occur. This results in undefined behavior when `self - rhs > ", stringify!($SelfT), -"::max_value()` or `self - rhs < ", stringify!($SelfT), "::min_value()`."), - #[unstable( - feature = "unchecked_math", - reason = "niche optimization path", - issue = "none", - )] - #[must_use = "this returns the result of the operation, \ - without modifying the original"] - #[inline] - pub unsafe fn unchecked_sub(self, rhs: Self) -> Self { - intrinsics::unchecked_sub(self, rhs) - } + /// Unchecked integer subtraction. Computes `self - rhs`, assuming overflow + /// cannot occur. This results in undefined behavior when `self - rhs > Self::MAX` + /// or `self - rhs < Self::MIN`". + #[unstable( + feature = "unchecked_math", + reason = "niche optimization path", + issue = "none", + )] + #[must_use = "this returns the result of the operation, without modifying the original"] + #[inline] + pub unsafe fn unchecked_sub(self, rhs: Self) -> Self { + intrinsics::unchecked_sub(self, rhs) } doc_comment! { @@ -3065,21 +3044,18 @@ assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(2), None);", $EndFeature, " } } - doc_comment! { - concat!("Unchecked integer multiplication. Computes `self * rhs, assuming overflow -cannot occur. This results in undefined behavior when `self * rhs > ", stringify!($SelfT), -"::max_value()` or `self * rhs < ", stringify!($SelfT), "::min_value()`."), - #[unstable( - feature = "unchecked_math", - reason = "niche optimization path", - issue = "none", - )] - #[must_use = "this returns the result of the operation, \ - without modifying the original"] - #[inline] - pub unsafe fn unchecked_mul(self, rhs: Self) -> Self { - intrinsics::unchecked_mul(self, rhs) - } + /// Unchecked integer multiplication. Computes `self * rhs`, assuming overflow + /// cannot occur. This results in undefined behavior when `self * rhs > Self::MAX` + /// or `self * rhs < Self::MIN`. + #[unstable( + feature = "unchecked_math", + reason = "niche optimization path", + issue = "none", + )] + #[must_use = "this returns the result of the operation, without modifying the original"] + #[inline] + pub unsafe fn unchecked_mul(self, rhs: Self) -> Self { + intrinsics::unchecked_mul(self, rhs) } doc_comment! { @@ -3366,7 +3342,7 @@ assert_eq!((", stringify!($SelfT), "::MAX).saturating_mul(10), ", stringify!($Se pub const fn saturating_mul(self, rhs: Self) -> Self { match self.checked_mul(rhs) { Some(x) => x, - None => Self::max_value(), + None => Self::MAX, } } } @@ -3393,7 +3369,7 @@ $EndFeature, " pub const fn saturating_pow(self, exp: u32) -> Self { match self.checked_pow(exp) { Some(x) => x, - None => Self::max_value(), + None => Self::MAX, } } } @@ -4080,7 +4056,7 @@ Basic usage: } } - doc_comment! { + doc_comment! { concat!("Performs Euclidean division. Since, for the positive integers, all common @@ -4178,7 +4154,7 @@ assert!(!10", stringify!($SelfT), ".is_power_of_two());", $EndFeature, " // (such as intel pre-haswell) have more efficient ctlz // intrinsics when the argument is non-zero. let z = unsafe { intrinsics::ctlz_nonzero(p) }; - <$SelfT>::max_value() >> z + <$SelfT>::MAX >> z } doc_comment! { @@ -4456,33 +4432,27 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), } } - doc_comment! { - concat!("**This method is soft-deprecated.** - -Although using it won’t cause compilation warning, -new code should use [`", stringify!($SelfT), "::MIN", "`](#associatedconstant.MIN) instead. - -Returns the smallest value that can be represented by this integer type."), - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_promotable] - #[inline(always)] - #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")] - pub const fn min_value() -> Self { Self::MIN } - } - - doc_comment! { - concat!("**This method is soft-deprecated.** - -Although using it won’t cause compilation warning, -new code should use [`", stringify!($SelfT), "::MAX", "`](#associatedconstant.MAX) instead. - -Returns the largest value that can be represented by this integer type."), - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_promotable] - #[inline(always)] - #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")] - pub const fn max_value() -> Self { Self::MAX } - } + /// Returns the smallest value that can be represented by this integer type. + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_promotable] + #[inline(always)] + #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")] + #[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant MIN is now prefered", + )] + pub const fn min_value() -> Self { Self::MIN } + + /// Returns the largest value that can be represented by this integer type. + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_promotable] + #[inline(always)] + #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")] + #[rustc_deprecated( + since = "1.46.0", + reason = "The associated constant MAX is now prefered", + )] + pub const fn max_value() -> Self { Self::MAX } } } @@ -5160,9 +5130,9 @@ trait FromStrRadixHelper: PartialOrd + Copy { macro_rules! doit { ($($t:ty)*) => ($(impl FromStrRadixHelper for $t { #[inline] - fn min_value() -> Self { Self::min_value() } + fn min_value() -> Self { Self::MIN } #[inline] - fn max_value() -> Self { Self::max_value() } + fn max_value() -> Self { Self::MAX } #[inline] fn from_u32(u: u32) -> Self { u as Self } #[inline] diff --git a/src/libcore/num/u128.rs b/src/libcore/num/u128.rs index dd45ff141539f..b9a83a55ced40 100644 --- a/src/libcore/num/u128.rs +++ b/src/libcore/num/u128.rs @@ -1,9 +1,6 @@ //! The 128-bit unsigned integer type. //! //! *[See also the `u128` primitive type](../../std/primitive.u128.html).* -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "i128", since = "1.26.0")] int_module! { u128, #[stable(feature = "i128", since="1.26.0")] } diff --git a/src/libcore/num/u16.rs b/src/libcore/num/u16.rs index 738071643b639..b481755c8d359 100644 --- a/src/libcore/num/u16.rs +++ b/src/libcore/num/u16.rs @@ -1,9 +1,6 @@ //! The 16-bit unsigned integer type. //! //! *[See also the `u16` primitive type](../../std/primitive.u16.html).* -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/u32.rs b/src/libcore/num/u32.rs index 9800c9099748f..7355b6c19867e 100644 --- a/src/libcore/num/u32.rs +++ b/src/libcore/num/u32.rs @@ -1,9 +1,6 @@ //! The 32-bit unsigned integer type. //! //! *[See also the `u32` primitive type](../../std/primitive.u32.html).* -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/u64.rs b/src/libcore/num/u64.rs index fb686c396f033..2da5f013f054b 100644 --- a/src/libcore/num/u64.rs +++ b/src/libcore/num/u64.rs @@ -1,9 +1,6 @@ //! The 64-bit unsigned integer type. //! //! *[See also the `u64` primitive type](../../std/primitive.u64.html).* -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/u8.rs b/src/libcore/num/u8.rs index c03cbdda25dbb..76d3d70d9e999 100644 --- a/src/libcore/num/u8.rs +++ b/src/libcore/num/u8.rs @@ -1,9 +1,6 @@ //! The 8-bit unsigned integer type. //! //! *[See also the `u8` primitive type](../../std/primitive.u8.html).* -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/usize.rs b/src/libcore/num/usize.rs index a893041615244..fe1325754598f 100644 --- a/src/libcore/num/usize.rs +++ b/src/libcore/num/usize.rs @@ -1,9 +1,6 @@ //! The pointer-sized unsigned integer type. //! //! *[See also the `usize` primitive type](../../std/primitive.usize.html).* -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/wrapping.rs b/src/libcore/num/wrapping.rs index 82fa6acfbd62a..e5b24a4f88a08 100644 --- a/src/libcore/num/wrapping.rs +++ b/src/libcore/num/wrapping.rs @@ -338,12 +338,12 @@ Basic usage: use std::num::Wrapping; assert_eq!(>::min_value(), ", -"Wrapping(", stringify!($t), "::min_value())); +"Wrapping(", stringify!($t), "::MIN)); ```"), #[unstable(feature = "wrapping_int_impl", issue = "32463")] #[inline] pub const fn min_value() -> Self { - Wrapping(<$t>::min_value()) + Wrapping(<$t>::MIN) } } @@ -359,12 +359,12 @@ Basic usage: use std::num::Wrapping; assert_eq!(>::max_value(), ", -"Wrapping(", stringify!($t), "::max_value())); +"Wrapping(", stringify!($t), "::MAX)); ```"), #[unstable(feature = "wrapping_int_impl", issue = "32463")] #[inline] pub const fn max_value() -> Self { - Wrapping(<$t>::max_value()) + Wrapping(<$t>::MAX) } } @@ -702,7 +702,7 @@ Basic usage: #![feature(wrapping_int_impl)] use std::num::Wrapping; -let n = Wrapping(", stringify!($t), "::max_value()) >> 2; +let n = Wrapping(", stringify!($t), "::MAX) >> 2; assert_eq!(n.leading_zeros(), 3); ```"), @@ -731,8 +731,8 @@ use std::num::Wrapping; assert_eq!(Wrapping(100", stringify!($t), ").abs(), Wrapping(100)); assert_eq!(Wrapping(-100", stringify!($t), ").abs(), Wrapping(100)); -assert_eq!(Wrapping(", stringify!($t), "::min_value()).abs(), Wrapping(", stringify!($t), -"::min_value())); +assert_eq!(Wrapping(", stringify!($t), "::MIN).abs(), Wrapping(", stringify!($t), +"::MIN)); assert_eq!(Wrapping(-128i8).abs().0 as u8, 128u8); ```"), #[inline] @@ -831,7 +831,7 @@ Basic usage: #![feature(wrapping_int_impl)] use std::num::Wrapping; -let n = Wrapping(", stringify!($t), "::max_value()) >> 2; +let n = Wrapping(", stringify!($t), "::MAX) >> 2; assert_eq!(n.leading_zeros(), 2); ```"), diff --git a/src/libcore/ptr/const_ptr.rs b/src/libcore/ptr/const_ptr.rs index 835183d171a79..e39d18d7733a2 100644 --- a/src/libcore/ptr/const_ptr.rs +++ b/src/libcore/ptr/const_ptr.rs @@ -291,7 +291,7 @@ impl *const T { T: Sized, { let pointee_size = mem::size_of::(); - assert!(0 < pointee_size && pointee_size <= isize::max_value() as usize); + assert!(0 < pointee_size && pointee_size <= isize::MAX as usize); intrinsics::ptr_offset_from(self, origin) } @@ -336,7 +336,7 @@ impl *const T { T: Sized, { let pointee_size = mem::size_of::(); - assert!(0 < pointee_size && pointee_size <= isize::max_value() as usize); + assert!(0 < pointee_size && pointee_size <= isize::MAX as usize); let d = isize::wrapping_sub(self as _, origin as _); d.wrapping_div(pointee_size as _) diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs index ecc70adda4111..57d0008e6f8a2 100644 --- a/src/libcore/ptr/mod.rs +++ b/src/libcore/ptr/mod.rs @@ -1128,7 +1128,7 @@ pub(crate) unsafe fn align_offset(p: *const T, a: usize) -> usize { // // Note, that we use wrapping operations here intentionally – the original formula // uses e.g., subtraction `mod n`. It is entirely fine to do them `mod - // usize::max_value()` instead, because we take the result `mod n` at the end + // usize::MAX` instead, because we take the result `mod n` at the end // anyway. inverse = inverse.wrapping_mul(2usize.wrapping_sub(x.wrapping_mul(inverse))); if going_mod >= m { @@ -1193,7 +1193,7 @@ pub(crate) unsafe fn align_offset(p: *const T, a: usize) -> usize { } // Cannot be aligned at all. - usize::max_value() + usize::MAX } /// Compares raw pointers for equality. diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index ff333f77334f7..8f0b662aa28e9 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -3043,16 +3043,12 @@ impl SliceIndex<[T]> for ops::RangeInclusive { #[inline] fn get(self, slice: &[T]) -> Option<&[T]> { - if *self.end() == usize::max_value() { - None - } else { - (*self.start()..self.end() + 1).get(slice) - } + if *self.end() == usize::MAX { None } else { (*self.start()..self.end() + 1).get(slice) } } #[inline] fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]> { - if *self.end() == usize::max_value() { + if *self.end() == usize::MAX { None } else { (*self.start()..self.end() + 1).get_mut(slice) @@ -3071,7 +3067,7 @@ impl SliceIndex<[T]> for ops::RangeInclusive { #[inline] fn index(self, slice: &[T]) -> &[T] { - if *self.end() == usize::max_value() { + if *self.end() == usize::MAX { slice_index_overflow_fail(); } (*self.start()..self.end() + 1).index(slice) @@ -3079,7 +3075,7 @@ impl SliceIndex<[T]> for ops::RangeInclusive { #[inline] fn index_mut(self, slice: &mut [T]) -> &mut [T] { - if *self.end() == usize::max_value() { + if *self.end() == usize::MAX { slice_index_overflow_fail(); } (*self.start()..self.end() + 1).index_mut(slice) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 316c2cd55acea..6c4b28499a60b 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -1651,7 +1651,7 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> { // Ascii case, try to skip forward quickly. // When the pointer is aligned, read 2 words of data per iteration // until we find a word containing a non-ascii byte. - if align != usize::max_value() && align.wrapping_sub(index) % usize_bytes == 0 { + if align != usize::MAX && align.wrapping_sub(index) % usize_bytes == 0 { let ptr = v.as_ptr(); while index < blocks_end { // SAFETY: since `align - index` and `ascii_block_size` are @@ -2083,7 +2083,7 @@ mod traits { type Output = str; #[inline] fn get(self, slice: &str) -> Option<&Self::Output> { - if *self.end() == usize::max_value() { + if *self.end() == usize::MAX { None } else { (*self.start()..self.end() + 1).get(slice) @@ -2091,7 +2091,7 @@ mod traits { } #[inline] fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output> { - if *self.end() == usize::max_value() { + if *self.end() == usize::MAX { None } else { (*self.start()..self.end() + 1).get_mut(slice) @@ -2107,14 +2107,14 @@ mod traits { } #[inline] fn index(self, slice: &str) -> &Self::Output { - if *self.end() == usize::max_value() { + if *self.end() == usize::MAX { str_index_overflow_fail(); } (*self.start()..self.end() + 1).index(slice) } #[inline] fn index_mut(self, slice: &mut str) -> &mut Self::Output { - if *self.end() == usize::max_value() { + if *self.end() == usize::MAX { str_index_overflow_fail(); } (*self.start()..self.end() + 1).index_mut(slice) @@ -2140,11 +2140,11 @@ mod traits { type Output = str; #[inline] fn get(self, slice: &str) -> Option<&Self::Output> { - if self.end == usize::max_value() { None } else { (..self.end + 1).get(slice) } + if self.end == usize::MAX { None } else { (..self.end + 1).get(slice) } } #[inline] fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output> { - if self.end == usize::max_value() { None } else { (..self.end + 1).get_mut(slice) } + if self.end == usize::MAX { None } else { (..self.end + 1).get_mut(slice) } } #[inline] unsafe fn get_unchecked(self, slice: &str) -> &Self::Output { @@ -2156,14 +2156,14 @@ mod traits { } #[inline] fn index(self, slice: &str) -> &Self::Output { - if self.end == usize::max_value() { + if self.end == usize::MAX { str_index_overflow_fail(); } (..self.end + 1).index(slice) } #[inline] fn index_mut(self, slice: &mut str) -> &mut Self::Output { - if self.end == usize::max_value() { + if self.end == usize::MAX { str_index_overflow_fail(); } (..self.end + 1).index_mut(slice) diff --git a/src/libcore/tests/num/mod.rs b/src/libcore/tests/num/mod.rs index 181bbb8e18784..939f1325c8499 100644 --- a/src/libcore/tests/num/mod.rs +++ b/src/libcore/tests/num/mod.rs @@ -140,8 +140,8 @@ macro_rules! test_impl_from { ($fn_name: ident, $Small: ty, $Large: ty) => { #[test] fn $fn_name() { - let small_max = <$Small>::max_value(); - let small_min = <$Small>::min_value(); + let small_max = <$Small>::MAX; + let small_min = <$Small>::MIN; let large_max: $Large = small_max.into(); let large_min: $Large = small_min.into(); assert_eq!(large_max as $Small, small_max); @@ -248,8 +248,8 @@ macro_rules! test_impl_try_from_always_ok { ($fn_name:ident, $source:ty, $target: ty) => { #[test] fn $fn_name() { - let max = <$source>::max_value(); - let min = <$source>::min_value(); + let max = <$source>::MAX; + let min = <$source>::MIN; let zero: $source = 0; assert_eq!(<$target as TryFrom<$source>>::try_from(max).unwrap(), max as $target); assert_eq!(<$target as TryFrom<$source>>::try_from(min).unwrap(), min as $target); @@ -361,8 +361,8 @@ macro_rules! test_impl_try_from_signed_to_unsigned_upper_ok { ($fn_name:ident, $source:ty, $target:ty) => { #[test] fn $fn_name() { - let max = <$source>::max_value(); - let min = <$source>::min_value(); + let max = <$source>::MAX; + let min = <$source>::MIN; let zero: $source = 0; let neg_one: $source = -1; assert_eq!(<$target as TryFrom<$source>>::try_from(max).unwrap(), max as $target); @@ -426,8 +426,8 @@ macro_rules! test_impl_try_from_unsigned_to_signed_upper_err { ($fn_name:ident, $source:ty, $target:ty) => { #[test] fn $fn_name() { - let max = <$source>::max_value(); - let min = <$source>::min_value(); + let max = <$source>::MAX; + let min = <$source>::MIN; let zero: $source = 0; assert!(<$target as TryFrom<$source>>::try_from(max).is_err()); assert_eq!(<$target as TryFrom<$source>>::try_from(min).unwrap(), min as $target); @@ -487,11 +487,11 @@ macro_rules! test_impl_try_from_same_sign_err { ($fn_name:ident, $source:ty, $target:ty) => { #[test] fn $fn_name() { - let max = <$source>::max_value(); - let min = <$source>::min_value(); + let max = <$source>::MAX; + let min = <$source>::MIN; let zero: $source = 0; - let t_max = <$target>::max_value(); - let t_min = <$target>::min_value(); + let t_max = <$target>::MAX; + let t_min = <$target>::MIN; assert!(<$target as TryFrom<$source>>::try_from(max).is_err()); if min != 0 { assert!(<$target as TryFrom<$source>>::try_from(min).is_err()); @@ -576,11 +576,11 @@ macro_rules! test_impl_try_from_signed_to_unsigned_err { ($fn_name:ident, $source:ty, $target:ty) => { #[test] fn $fn_name() { - let max = <$source>::max_value(); - let min = <$source>::min_value(); + let max = <$source>::MAX; + let min = <$source>::MIN; let zero: $source = 0; - let t_max = <$target>::max_value(); - let t_min = <$target>::min_value(); + let t_max = <$target>::MAX; + let t_min = <$target>::MIN; assert!(<$target as TryFrom<$source>>::try_from(max).is_err()); assert!(<$target as TryFrom<$source>>::try_from(min).is_err()); assert_eq!(<$target as TryFrom<$source>>::try_from(zero).unwrap(), zero as $target); diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs index a008b3319f39a..9fea34d668fcc 100644 --- a/src/libcore/tests/ptr.rs +++ b/src/libcore/tests/ptr.rs @@ -357,7 +357,7 @@ fn align_offset_weird_strides() { unsafe fn test_weird_stride(ptr: *const T, align: usize) -> bool { let numptr = ptr as usize; - let mut expected = usize::max_value(); + let mut expected = usize::MAX; // Naive but definitely correct way to find the *first* aligned element of stride::. for el in 0..align { if (numptr + el * ::std::mem::size_of::()) % align == 0 { diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs index 54a585415bce2..cd46117f76322 100644 --- a/src/libcore/tests/slice.rs +++ b/src/libcore/tests/slice.rs @@ -1691,8 +1691,8 @@ fn test_copy_within_panics_src_inverted() { #[should_panic(expected = "attempted to index slice up to maximum usize")] fn test_copy_within_panics_src_out_of_bounds() { let mut bytes = *b"Hello, World!"; - // an inclusive range ending at usize::max_value() would make src_end overflow - bytes.copy_within(usize::max_value()..=usize::max_value(), 0); + // an inclusive range ending at usize::MAX would make src_end overflow + bytes.copy_within(usize::MAX..=usize::MAX, 0); } #[test] diff --git a/src/librustc_apfloat/lib.rs b/src/librustc_apfloat/lib.rs index 09a069ab3136d..ba3adc4a135cb 100644 --- a/src/librustc_apfloat/lib.rs +++ b/src/librustc_apfloat/lib.rs @@ -133,9 +133,9 @@ impl Neg for Round { pub type ExpInt = i16; // \c ilogb error results. -pub const IEK_INF: ExpInt = ExpInt::max_value(); -pub const IEK_NAN: ExpInt = ExpInt::min_value(); -pub const IEK_ZERO: ExpInt = ExpInt::min_value() + 1; +pub const IEK_INF: ExpInt = ExpInt::MAX; +pub const IEK_NAN: ExpInt = ExpInt::MIN; +pub const IEK_ZERO: ExpInt = ExpInt::MIN + 1; #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub struct ParseError(pub &'static str); diff --git a/src/librustc_apfloat/tests/ieee.rs b/src/librustc_apfloat/tests/ieee.rs index e5b06cf225d16..2d8bb7d1e8e03 100644 --- a/src/librustc_apfloat/tests/ieee.rs +++ b/src/librustc_apfloat/tests/ieee.rs @@ -2997,8 +2997,8 @@ fn scalbn() { assert!(smallest_f64.scalbn(2099).is_infinite()); // Test for integer overflows when adding to exponent. - assert!(smallest_f64.scalbn(-ExpInt::max_value()).is_pos_zero()); - assert!(largest_f64.scalbn(ExpInt::max_value()).is_infinite()); + assert!(smallest_f64.scalbn(-ExpInt::MAX).is_pos_zero()); + assert!(largest_f64.scalbn(ExpInt::MAX).is_infinite()); assert!(largest_denormal_f64.bitwise_eq(largest_denormal_f64.scalbn(0),)); assert!(neg_largest_denormal_f64.bitwise_eq(neg_largest_denormal_f64.scalbn(0),)); diff --git a/src/librustc_data_structures/base_n/tests.rs b/src/librustc_data_structures/base_n/tests.rs index a86f991cd0e0d..b68ef1eb7f4c4 100644 --- a/src/librustc_data_structures/base_n/tests.rs +++ b/src/librustc_data_structures/base_n/tests.rs @@ -12,8 +12,8 @@ fn test_encode() { test(35, base); test(36, base); test(37, base); - test(u64::max_value() as u128, base); - test(u128::max_value(), base); + test(u64::MAX as u128, base); + test(u128::MAX, base); for i in 0..1_000 { test(i * 983, base); diff --git a/src/librustc_expand/proc_macro_server.rs b/src/librustc_expand/proc_macro_server.rs index 36af83711f7e4..60af6eb967ded 100644 --- a/src/librustc_expand/proc_macro_server.rs +++ b/src/librustc_expand/proc_macro_server.rs @@ -580,10 +580,10 @@ impl server::Literal for Rustc<'_> { }; // Bounds check the values, preventing addition overflow and OOB spans. - if start > u32::max_value() as usize - || end > u32::max_value() as usize - || (u32::max_value() - start as u32) < span.lo().to_u32() - || (u32::max_value() - end as u32) < span.lo().to_u32() + if start > u32::MAX as usize + || end > u32::MAX as usize + || (u32::MAX - start as u32) < span.lo().to_u32() + || (u32::MAX - end as u32) < span.lo().to_u32() || start >= end || end > length { diff --git a/src/librustc_lexer/src/unescape.rs b/src/librustc_lexer/src/unescape.rs index 2a9e1b7cbc346..697d25fdb585b 100644 --- a/src/librustc_lexer/src/unescape.rs +++ b/src/librustc_lexer/src/unescape.rs @@ -335,7 +335,7 @@ where fn byte_from_char(c: char) -> u8 { let res = c as u32; - assert!(res <= u8::max_value() as u32, "guaranteed because of Mode::ByteStr"); + assert!(res <= u8::MAX as u32, "guaranteed because of Mode::ByteStr"); res as u8 } diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 703c2a7a443a9..a67c09b892379 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -108,23 +108,23 @@ fn lint_overflowing_range_endpoint<'a, 'tcx>( // warnings are consistent between 32- and 64-bit platforms. fn int_ty_range(int_ty: ast::IntTy) -> (i128, i128) { match int_ty { - ast::IntTy::Isize => (i64::min_value() as i128, i64::max_value() as i128), - ast::IntTy::I8 => (i8::min_value() as i64 as i128, i8::max_value() as i128), - ast::IntTy::I16 => (i16::min_value() as i64 as i128, i16::max_value() as i128), - ast::IntTy::I32 => (i32::min_value() as i64 as i128, i32::max_value() as i128), - ast::IntTy::I64 => (i64::min_value() as i128, i64::max_value() as i128), - ast::IntTy::I128 => (i128::min_value() as i128, i128::max_value()), + ast::IntTy::Isize => (i64::MIN as i128, i64::MAX as i128), + ast::IntTy::I8 => (i8::MIN as i64 as i128, i8::MAX as i128), + ast::IntTy::I16 => (i16::MIN as i64 as i128, i16::MAX as i128), + ast::IntTy::I32 => (i32::MIN as i64 as i128, i32::MAX as i128), + ast::IntTy::I64 => (i64::MIN as i128, i64::MAX as i128), + ast::IntTy::I128 => (i128::MIN as i128, i128::MAX), } } fn uint_ty_range(uint_ty: ast::UintTy) -> (u128, u128) { match uint_ty { - ast::UintTy::Usize => (u64::min_value() as u128, u64::max_value() as u128), - ast::UintTy::U8 => (u8::min_value() as u128, u8::max_value() as u128), - ast::UintTy::U16 => (u16::min_value() as u128, u16::max_value() as u128), - ast::UintTy::U32 => (u32::min_value() as u128, u32::max_value() as u128), - ast::UintTy::U64 => (u64::min_value() as u128, u64::max_value() as u128), - ast::UintTy::U128 => (u128::min_value(), u128::max_value()), + ast::UintTy::Usize => (u64::MIN as u128, u64::MAX as u128), + ast::UintTy::U8 => (u8::MIN as u128, u8::MAX as u128), + ast::UintTy::U16 => (u16::MIN as u128, u16::MAX as u128), + ast::UintTy::U32 => (u32::MIN as u128, u32::MAX as u128), + ast::UintTy::U64 => (u64::MIN as u128, u64::MAX as u128), + ast::UintTy::U128 => (u128::MIN, u128::MAX), } } diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index db29e9538999a..7303dd50a8c12 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -930,7 +930,7 @@ impl<'a> CrateLoader<'a> { src: ExternCrateSource::Path, span, // to have the least priority in `update_extern_crate` - path_len: usize::max_value(), + path_len: usize::MAX, dependency_of: LOCAL_CRATE, }, ); diff --git a/src/librustc_mir_build/build/matches/simplify.rs b/src/librustc_mir_build/build/matches/simplify.rs index 09543cd1ce4e6..2917a771a2cf8 100644 --- a/src/librustc_mir_build/build/matches/simplify.rs +++ b/src/librustc_mir_build/build/matches/simplify.rs @@ -160,13 +160,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } ty::Int(ity) => { let size = Integer::from_attr(&tcx, SignedInt(ity)).size(); - let max = truncate(u128::max_value(), size); + let max = truncate(u128::MAX, size); let bias = 1u128 << (size.bits() - 1); (Some((0, max, size)), bias) } ty::Uint(uty) => { let size = Integer::from_attr(&tcx, UnsignedInt(uty)).size(); - let max = truncate(u128::max_value(), size); + let max = truncate(u128::MAX, size); (Some((0, max, size)), 0) } _ => (None, 0), diff --git a/src/librustc_mir_build/hair/pattern/_match.rs b/src/librustc_mir_build/hair/pattern/_match.rs index 575ddcef99715..54029d38dc687 100644 --- a/src/librustc_mir_build/hair/pattern/_match.rs +++ b/src/librustc_mir_build/hair/pattern/_match.rs @@ -1520,7 +1520,7 @@ fn all_constructors<'a, 'tcx>( } ty::Uint(uty) => { let size = Integer::from_attr(&cx.tcx, UnsignedInt(uty)).size(); - let max = truncate(u128::max_value(), size); + let max = truncate(u128::MAX, size); vec![make_range(0, max)] } _ => { diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 3b49b3b6ff7d2..870f139680490 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -1817,7 +1817,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { // // use std::u8; // bring module u8 in scope // fn f() -> u8 { // OK, resolves to primitive u8, not to std::u8 - // u8::max_value() // OK, resolves to associated function ::max_value, + // u8::MAX // OK, resolves to associated function ::max_value, // // not to non-existent std::u8::max_value // } // diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 3bd68a9c656ce..31b2ee3595c0b 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -1120,7 +1120,7 @@ fn id_from_node_id(id: NodeId, scx: &SaveContext<'_, '_>) -> rls_data::Id { } fn null_id() -> rls_data::Id { - rls_data::Id { krate: u32::max_value(), index: u32::max_value() } + rls_data::Id { krate: u32::MAX, index: u32::MAX } } fn lower_attributes(attrs: Vec, scx: &SaveContext<'_, '_>) -> Vec { diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs index 5bdd7b67723b8..411a6eecbba15 100644 --- a/src/librustc_session/config.rs +++ b/src/librustc_session/config.rs @@ -1031,7 +1031,7 @@ pub fn get_cmd_lint_options( // HACK: forbid is always specified last, so it can't be overridden. // FIXME: remove this once is // fixed and `forbid` works as expected. - usize::max_value() + usize::MAX } else { passed_arg_pos }; diff --git a/src/librustc_span/lib.rs b/src/librustc_span/lib.rs index c7d2205eb1c27..09c179b1a7a12 100644 --- a/src/librustc_span/lib.rs +++ b/src/librustc_span/lib.rs @@ -1215,7 +1215,7 @@ impl SourceFile { hasher.finish::() }; let end_pos = start_pos.to_usize() + src.len(); - assert!(end_pos <= u32::max_value() as usize); + assert!(end_pos <= u32::MAX as usize); let (lines, multibyte_chars, non_narrow_chars) = analyze_source_file::analyze_source_file(&src[..], start_pos); diff --git a/src/librustc_span/source_map.rs b/src/librustc_span/source_map.rs index c33c1dd29cb72..4b5bce1db2628 100644 --- a/src/librustc_span/source_map.rs +++ b/src/librustc_span/source_map.rs @@ -819,9 +819,7 @@ impl SourceMap { // Disregard indexes that are at the start or end of their spans, they can't fit bigger // characters. - if (!forwards && end_index == usize::min_value()) - || (forwards && start_index == usize::max_value()) - { + if (!forwards && end_index == usize::MIN) || (forwards && start_index == usize::MAX) { debug!("find_width_of_character_at_span: start or end of span, cannot be multibyte"); return 1; } diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 8ff19557a3063..e40bbd6851c65 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -4,9 +4,6 @@ //! *[See also the `f32` primitive type](../../std/primitive.f32.html).* //! //! Mathematically significant numbers are provided in the `consts` sub-module. -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "rust1", since = "1.0.0")] #![allow(missing_docs)] @@ -19,12 +16,16 @@ use crate::sys::cmath; #[stable(feature = "rust1", since = "1.0.0")] pub use core::f32::consts; #[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated_in_future)] pub use core::f32::{DIGITS, EPSILON, MANTISSA_DIGITS, RADIX}; #[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated_in_future)] pub use core::f32::{INFINITY, MAX_10_EXP, NAN, NEG_INFINITY}; #[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated_in_future)] pub use core::f32::{MAX, MIN, MIN_POSITIVE}; #[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated_in_future)] pub use core::f32::{MAX_EXP, MIN_10_EXP, MIN_EXP}; #[cfg(not(test))] @@ -916,8 +917,7 @@ impl f32 { #[cfg(test)] mod tests { - use crate::f32; - use crate::f32::*; + use crate::f32::consts; use crate::num::FpCategory as Fp; use crate::num::*; @@ -928,14 +928,14 @@ mod tests { #[test] fn test_min_nan() { - assert_eq!(NAN.min(2.0), 2.0); - assert_eq!(2.0f32.min(NAN), 2.0); + assert_eq!(f32::NAN.min(2.0), 2.0); + assert_eq!(2.0f32.min(f32::NAN), 2.0); } #[test] fn test_max_nan() { - assert_eq!(NAN.max(2.0), 2.0); - assert_eq!(2.0f32.max(NAN), 2.0); + assert_eq!(f32::NAN.max(2.0), 2.0); + assert_eq!(2.0f32.max(f32::NAN), 2.0); } #[test] @@ -1158,52 +1158,52 @@ mod tests { #[test] fn test_abs() { - assert_eq!(INFINITY.abs(), INFINITY); + assert_eq!(f32::INFINITY.abs(), f32::INFINITY); assert_eq!(1f32.abs(), 1f32); assert_eq!(0f32.abs(), 0f32); assert_eq!((-0f32).abs(), 0f32); assert_eq!((-1f32).abs(), 1f32); - assert_eq!(NEG_INFINITY.abs(), INFINITY); - assert_eq!((1f32 / NEG_INFINITY).abs(), 0f32); - assert!(NAN.abs().is_nan()); + assert_eq!(f32::NEG_INFINITY.abs(), f32::INFINITY); + assert_eq!((1f32 / f32::NEG_INFINITY).abs(), 0f32); + assert!(f32::NAN.abs().is_nan()); } #[test] fn test_signum() { - assert_eq!(INFINITY.signum(), 1f32); + assert_eq!(f32::INFINITY.signum(), 1f32); assert_eq!(1f32.signum(), 1f32); assert_eq!(0f32.signum(), 1f32); assert_eq!((-0f32).signum(), -1f32); assert_eq!((-1f32).signum(), -1f32); - assert_eq!(NEG_INFINITY.signum(), -1f32); - assert_eq!((1f32 / NEG_INFINITY).signum(), -1f32); - assert!(NAN.signum().is_nan()); + assert_eq!(f32::NEG_INFINITY.signum(), -1f32); + assert_eq!((1f32 / f32::NEG_INFINITY).signum(), -1f32); + assert!(f32::NAN.signum().is_nan()); } #[test] fn test_is_sign_positive() { - assert!(INFINITY.is_sign_positive()); + assert!(f32::INFINITY.is_sign_positive()); assert!(1f32.is_sign_positive()); assert!(0f32.is_sign_positive()); assert!(!(-0f32).is_sign_positive()); assert!(!(-1f32).is_sign_positive()); - assert!(!NEG_INFINITY.is_sign_positive()); - assert!(!(1f32 / NEG_INFINITY).is_sign_positive()); - assert!(NAN.is_sign_positive()); - assert!(!(-NAN).is_sign_positive()); + assert!(!f32::NEG_INFINITY.is_sign_positive()); + assert!(!(1f32 / f32::NEG_INFINITY).is_sign_positive()); + assert!(f32::NAN.is_sign_positive()); + assert!(!(-f32::NAN).is_sign_positive()); } #[test] fn test_is_sign_negative() { - assert!(!INFINITY.is_sign_negative()); + assert!(!f32::INFINITY.is_sign_negative()); assert!(!1f32.is_sign_negative()); assert!(!0f32.is_sign_negative()); assert!((-0f32).is_sign_negative()); assert!((-1f32).is_sign_negative()); - assert!(NEG_INFINITY.is_sign_negative()); - assert!((1f32 / NEG_INFINITY).is_sign_negative()); - assert!(!NAN.is_sign_negative()); - assert!((-NAN).is_sign_negative()); + assert!(f32::NEG_INFINITY.is_sign_negative()); + assert!((1f32 / f32::NEG_INFINITY).is_sign_negative()); + assert!(!f32::NAN.is_sign_negative()); + assert!((-f32::NAN).is_sign_negative()); } #[test] @@ -1268,13 +1268,13 @@ mod tests { #[test] fn test_sqrt_domain() { - assert!(NAN.sqrt().is_nan()); - assert!(NEG_INFINITY.sqrt().is_nan()); + assert!(f32::NAN.sqrt().is_nan()); + assert!(f32::NEG_INFINITY.sqrt().is_nan()); assert!((-1.0f32).sqrt().is_nan()); assert_eq!((-0.0f32).sqrt(), -0.0); assert_eq!(0.0f32.sqrt(), 0.0); assert_eq!(1.0f32.sqrt(), 1.0); - assert_eq!(INFINITY.sqrt(), INFINITY); + assert_eq!(f32::INFINITY.sqrt(), f32::INFINITY); } #[test] @@ -1523,13 +1523,13 @@ mod tests { #[test] #[should_panic] fn test_clamp_min_is_nan() { - let _ = 1.0f32.clamp(NAN, 1.0); + let _ = 1.0f32.clamp(f32::NAN, 1.0); } #[test] #[should_panic] fn test_clamp_max_is_nan() { - let _ = 1.0f32.clamp(3.0, NAN); + let _ = 1.0f32.clamp(3.0, f32::NAN); } #[test] diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index d7845fd2c4ddc..22fdca7205fed 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -4,9 +4,6 @@ //! *[See also the `f64` primitive type](../../std/primitive.f64.html).* //! //! Mathematically significant numbers are provided in the `consts` sub-module. -//! -//! Although using these constants won’t cause compilation warnings, -//! new code should use the associated constants directly on the primitive type. #![stable(feature = "rust1", since = "1.0.0")] #![allow(missing_docs)] @@ -19,12 +16,16 @@ use crate::sys::cmath; #[stable(feature = "rust1", since = "1.0.0")] pub use core::f64::consts; #[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated_in_future)] pub use core::f64::{DIGITS, EPSILON, MANTISSA_DIGITS, RADIX}; #[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated_in_future)] pub use core::f64::{INFINITY, MAX_10_EXP, NAN, NEG_INFINITY}; #[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated_in_future)] pub use core::f64::{MAX, MIN, MIN_POSITIVE}; #[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated_in_future)] pub use core::f64::{MAX_EXP, MIN_10_EXP, MIN_EXP}; #[cfg(not(test))] @@ -943,8 +944,7 @@ impl f64 { #[cfg(test)] mod tests { - use crate::f64; - use crate::f64::*; + use crate::f64::consts; use crate::num::FpCategory as Fp; use crate::num::*; @@ -955,19 +955,19 @@ mod tests { #[test] fn test_min_nan() { - assert_eq!(NAN.min(2.0), 2.0); - assert_eq!(2.0f64.min(NAN), 2.0); + assert_eq!(f64::NAN.min(2.0), 2.0); + assert_eq!(2.0f64.min(f64::NAN), 2.0); } #[test] fn test_max_nan() { - assert_eq!(NAN.max(2.0), 2.0); - assert_eq!(2.0f64.max(NAN), 2.0); + assert_eq!(f64::NAN.max(2.0), 2.0); + assert_eq!(2.0f64.max(f64::NAN), 2.0); } #[test] fn test_nan() { - let nan: f64 = NAN; + let nan: f64 = f64::NAN; assert!(nan.is_nan()); assert!(!nan.is_infinite()); assert!(!nan.is_finite()); @@ -979,7 +979,7 @@ mod tests { #[test] fn test_infinity() { - let inf: f64 = INFINITY; + let inf: f64 = f64::INFINITY; assert!(inf.is_infinite()); assert!(!inf.is_finite()); assert!(inf.is_sign_positive()); @@ -991,7 +991,7 @@ mod tests { #[test] fn test_neg_infinity() { - let neg_inf: f64 = NEG_INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; assert!(neg_inf.is_infinite()); assert!(!neg_inf.is_finite()); assert!(!neg_inf.is_sign_positive()); @@ -1043,9 +1043,9 @@ mod tests { #[test] fn test_is_nan() { - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; assert!(nan.is_nan()); assert!(!0.0f64.is_nan()); assert!(!5.3f64.is_nan()); @@ -1056,9 +1056,9 @@ mod tests { #[test] fn test_is_infinite() { - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; assert!(!nan.is_infinite()); assert!(inf.is_infinite()); assert!(neg_inf.is_infinite()); @@ -1069,9 +1069,9 @@ mod tests { #[test] fn test_is_finite() { - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; assert!(!nan.is_finite()); assert!(!inf.is_finite()); assert!(!neg_inf.is_finite()); @@ -1083,9 +1083,9 @@ mod tests { #[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630 #[test] fn test_is_normal() { - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; let zero: f64 = 0.0f64; let neg_zero: f64 = -0.0; assert!(!nan.is_normal()); @@ -1101,9 +1101,9 @@ mod tests { #[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630 #[test] fn test_classify() { - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; let zero: f64 = 0.0f64; let neg_zero: f64 = -0.0; assert_eq!(nan.classify(), Fp::Nan); @@ -1187,59 +1187,59 @@ mod tests { #[test] fn test_abs() { - assert_eq!(INFINITY.abs(), INFINITY); + assert_eq!(f64::INFINITY.abs(), f64::INFINITY); assert_eq!(1f64.abs(), 1f64); assert_eq!(0f64.abs(), 0f64); assert_eq!((-0f64).abs(), 0f64); assert_eq!((-1f64).abs(), 1f64); - assert_eq!(NEG_INFINITY.abs(), INFINITY); - assert_eq!((1f64 / NEG_INFINITY).abs(), 0f64); - assert!(NAN.abs().is_nan()); + assert_eq!(f64::NEG_INFINITY.abs(), f64::INFINITY); + assert_eq!((1f64 / f64::NEG_INFINITY).abs(), 0f64); + assert!(f64::NAN.abs().is_nan()); } #[test] fn test_signum() { - assert_eq!(INFINITY.signum(), 1f64); + assert_eq!(f64::INFINITY.signum(), 1f64); assert_eq!(1f64.signum(), 1f64); assert_eq!(0f64.signum(), 1f64); assert_eq!((-0f64).signum(), -1f64); assert_eq!((-1f64).signum(), -1f64); - assert_eq!(NEG_INFINITY.signum(), -1f64); - assert_eq!((1f64 / NEG_INFINITY).signum(), -1f64); - assert!(NAN.signum().is_nan()); + assert_eq!(f64::NEG_INFINITY.signum(), -1f64); + assert_eq!((1f64 / f64::NEG_INFINITY).signum(), -1f64); + assert!(f64::NAN.signum().is_nan()); } #[test] fn test_is_sign_positive() { - assert!(INFINITY.is_sign_positive()); + assert!(f64::INFINITY.is_sign_positive()); assert!(1f64.is_sign_positive()); assert!(0f64.is_sign_positive()); assert!(!(-0f64).is_sign_positive()); assert!(!(-1f64).is_sign_positive()); - assert!(!NEG_INFINITY.is_sign_positive()); - assert!(!(1f64 / NEG_INFINITY).is_sign_positive()); - assert!(NAN.is_sign_positive()); - assert!(!(-NAN).is_sign_positive()); + assert!(!f64::NEG_INFINITY.is_sign_positive()); + assert!(!(1f64 / f64::NEG_INFINITY).is_sign_positive()); + assert!(f64::NAN.is_sign_positive()); + assert!(!(-f64::NAN).is_sign_positive()); } #[test] fn test_is_sign_negative() { - assert!(!INFINITY.is_sign_negative()); + assert!(!f64::INFINITY.is_sign_negative()); assert!(!1f64.is_sign_negative()); assert!(!0f64.is_sign_negative()); assert!((-0f64).is_sign_negative()); assert!((-1f64).is_sign_negative()); - assert!(NEG_INFINITY.is_sign_negative()); - assert!((1f64 / NEG_INFINITY).is_sign_negative()); - assert!(!NAN.is_sign_negative()); - assert!((-NAN).is_sign_negative()); + assert!(f64::NEG_INFINITY.is_sign_negative()); + assert!((1f64 / f64::NEG_INFINITY).is_sign_negative()); + assert!(!f64::NAN.is_sign_negative()); + assert!((-f64::NAN).is_sign_negative()); } #[test] fn test_mul_add() { - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; assert_approx_eq!(12.3f64.mul_add(4.5, 6.7), 62.05); assert_approx_eq!((-12.3f64).mul_add(-4.5, -6.7), 48.65); assert_approx_eq!(0.0f64.mul_add(8.9, 1.2), 1.2); @@ -1253,9 +1253,9 @@ mod tests { #[test] fn test_recip() { - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; assert_eq!(1.0f64.recip(), 1.0); assert_eq!(2.0f64.recip(), 0.5); assert_eq!((-0.4f64).recip(), -2.5); @@ -1267,9 +1267,9 @@ mod tests { #[test] fn test_powi() { - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; assert_eq!(1.0f64.powi(1), 1.0); assert_approx_eq!((-3.1f64).powi(2), 9.61); assert_approx_eq!(5.9f64.powi(-2), 0.028727); @@ -1281,9 +1281,9 @@ mod tests { #[test] fn test_powf() { - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; assert_eq!(1.0f64.powf(1.0), 1.0); assert_approx_eq!(3.4f64.powf(4.5), 246.408183); assert_approx_eq!(2.7f64.powf(-3.2), 0.041652); @@ -1297,13 +1297,13 @@ mod tests { #[test] fn test_sqrt_domain() { - assert!(NAN.sqrt().is_nan()); - assert!(NEG_INFINITY.sqrt().is_nan()); + assert!(f64::NAN.sqrt().is_nan()); + assert!(f64::NEG_INFINITY.sqrt().is_nan()); assert!((-1.0f64).sqrt().is_nan()); assert_eq!((-0.0f64).sqrt(), -0.0); assert_eq!(0.0f64.sqrt(), 0.0); assert_eq!(1.0f64.sqrt(), 1.0); - assert_eq!(INFINITY.sqrt(), INFINITY); + assert_eq!(f64::INFINITY.sqrt(), f64::INFINITY); } #[test] @@ -1312,9 +1312,9 @@ mod tests { assert_approx_eq!(2.718282, 1.0f64.exp()); assert_approx_eq!(148.413159, 5.0f64.exp()); - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; - let nan: f64 = NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; + let nan: f64 = f64::NAN; assert_eq!(inf, inf.exp()); assert_eq!(0.0, neg_inf.exp()); assert!(nan.exp().is_nan()); @@ -1325,9 +1325,9 @@ mod tests { assert_eq!(32.0, 5.0f64.exp2()); assert_eq!(1.0, 0.0f64.exp2()); - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; - let nan: f64 = NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; + let nan: f64 = f64::NAN; assert_eq!(inf, inf.exp2()); assert_eq!(0.0, neg_inf.exp2()); assert!(nan.exp2().is_nan()); @@ -1335,9 +1335,9 @@ mod tests { #[test] fn test_ln() { - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; assert_approx_eq!(1.0f64.exp().ln(), 1.0); assert!(nan.ln().is_nan()); assert_eq!(inf.ln(), inf); @@ -1350,9 +1350,9 @@ mod tests { #[test] fn test_log() { - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; assert_eq!(10.0f64.log(10.0), 1.0); assert_approx_eq!(2.3f64.log(3.5), 0.664858); assert_eq!(1.0f64.exp().log(1.0f64.exp()), 1.0); @@ -1368,9 +1368,9 @@ mod tests { #[test] fn test_log2() { - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; assert_approx_eq!(10.0f64.log2(), 3.321928); assert_approx_eq!(2.3f64.log2(), 1.201634); assert_approx_eq!(1.0f64.exp().log2(), 1.442695); @@ -1384,9 +1384,9 @@ mod tests { #[test] fn test_log10() { - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; assert_eq!(10.0f64.log10(), 1.0); assert_approx_eq!(2.3f64.log10(), 0.361728); assert_approx_eq!(1.0f64.exp().log10(), 0.434294); @@ -1402,9 +1402,9 @@ mod tests { #[test] fn test_to_degrees() { let pi: f64 = consts::PI; - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; assert_eq!(0.0f64.to_degrees(), 0.0); assert_approx_eq!((-5.8f64).to_degrees(), -332.315521); assert_eq!(pi.to_degrees(), 180.0); @@ -1416,9 +1416,9 @@ mod tests { #[test] fn test_to_radians() { let pi: f64 = consts::PI; - let nan: f64 = NAN; - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; + let nan: f64 = f64::NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; assert_eq!(0.0f64.to_radians(), 0.0); assert_approx_eq!(154.6f64.to_radians(), 2.698279); assert_approx_eq!((-332.31f64).to_radians(), -5.799903); @@ -1433,9 +1433,9 @@ mod tests { assert_eq!(0.0f64.asinh(), 0.0f64); assert_eq!((-0.0f64).asinh(), -0.0f64); - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; - let nan: f64 = NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; + let nan: f64 = f64::NAN; assert_eq!(inf.asinh(), inf); assert_eq!(neg_inf.asinh(), neg_inf); assert!(nan.asinh().is_nan()); @@ -1450,9 +1450,9 @@ mod tests { assert_eq!(1.0f64.acosh(), 0.0f64); assert!(0.999f64.acosh().is_nan()); - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; - let nan: f64 = NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; + let nan: f64 = f64::NAN; assert_eq!(inf.acosh(), inf); assert!(neg_inf.acosh().is_nan()); assert!(nan.acosh().is_nan()); @@ -1465,9 +1465,9 @@ mod tests { assert_eq!(0.0f64.atanh(), 0.0f64); assert_eq!((-0.0f64).atanh(), -0.0f64); - let inf: f64 = INFINITY; - let neg_inf: f64 = NEG_INFINITY; - let nan: f64 = NAN; + let inf: f64 = f64::INFINITY; + let neg_inf: f64 = f64::NEG_INFINITY; + let nan: f64 = f64::NAN; assert_eq!(1.0f64.atanh(), inf); assert_eq!((-1.0f64).atanh(), neg_inf); assert!(2f64.atanh().atanh().is_nan()); @@ -1546,13 +1546,13 @@ mod tests { #[test] #[should_panic] fn test_clamp_min_is_nan() { - let _ = 1.0f64.clamp(NAN, 1.0); + let _ = 1.0f64.clamp(f64::NAN, 1.0); } #[test] #[should_panic] fn test_clamp_max_is_nan() { - let _ = 1.0f64.clamp(3.0, NAN); + let _ = 1.0f64.clamp(3.0, f64::NAN); } #[test] diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 046b1a6888024..802f170585c9e 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -367,7 +367,7 @@ impl Seek for BufReader { // it should be safe to assume that remainder fits within an i64 as the alternative // means we managed to allocate 8 exbibytes and that's absurd. // But it's not out of the realm of possibility for some weird underlying reader to - // support seeking by i64::min_value() so we need to handle underflow when subtracting + // support seeking by i64::MIN so we need to handle underflow when subtracting // remainder. if let Some(offset) = n.checked_sub(remainder) { result = self.inner.seek(SeekFrom::Current(offset))?; @@ -1270,7 +1270,7 @@ mod tests { self.pos = self.pos.wrapping_add(n as u64); } SeekFrom::End(n) => { - self.pos = u64::max_value().wrapping_add(n as u64); + self.pos = u64::MAX.wrapping_add(n as u64); } } Ok(self.pos) @@ -1279,11 +1279,11 @@ mod tests { let mut reader = BufReader::with_capacity(5, PositionReader { pos: 0 }); assert_eq!(reader.fill_buf().ok(), Some(&[0, 1, 2, 3, 4][..])); - assert_eq!(reader.seek(SeekFrom::End(-5)).ok(), Some(u64::max_value() - 5)); + assert_eq!(reader.seek(SeekFrom::End(-5)).ok(), Some(u64::MAX - 5)); assert_eq!(reader.fill_buf().ok().map(|s| s.len()), Some(5)); // the following seek will require two underlying seeks let expected = 9223372036854775802; - assert_eq!(reader.seek(SeekFrom::Current(i64::min_value())).ok(), Some(expected)); + assert_eq!(reader.seek(SeekFrom::Current(i64::MIN)).ok(), Some(expected)); assert_eq!(reader.fill_buf().ok().map(|s| s.len()), Some(5)); // seeking to 0 should empty the buffer. assert_eq!(reader.seek(SeekFrom::Current(0)).ok(), Some(expected)); @@ -1321,7 +1321,7 @@ mod tests { // The following seek will require two underlying seeks. The first will // succeed but the second will fail. This should still invalidate the // buffer. - assert!(reader.seek(SeekFrom::Current(i64::min_value())).is_err()); + assert!(reader.seek(SeekFrom::Current(i64::MIN)).is_err()); assert_eq!(reader.buffer().len(), 0); } diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index f3e3fc81a5d82..39d2970f6ee4b 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -963,7 +963,7 @@ mod tests { #[cfg(target_pointer_width = "32")] fn vec_seek_and_write_past_usize_max() { let mut c = Cursor::new(Vec::new()); - c.set_position(::max_value() as u64 + 1); + c.set_position(::MAX as u64 + 1); assert!(c.write_all(&[1, 2, 3]).is_err()); } diff --git a/src/libstd/num.rs b/src/libstd/num.rs index de8acf8d9d472..b496c16a749cf 100644 --- a/src/libstd/num.rs +++ b/src/libstd/num.rs @@ -52,52 +52,43 @@ where #[cfg(test)] mod tests { use crate::ops::Mul; - use crate::u16; - use crate::u32; - use crate::u64; - use crate::u8; - use crate::usize; #[test] fn test_saturating_add_uint() { - use crate::usize::MAX; assert_eq!(3_usize.saturating_add(5_usize), 8_usize); - assert_eq!(3_usize.saturating_add(MAX - 1), MAX); - assert_eq!(MAX.saturating_add(MAX), MAX); - assert_eq!((MAX - 2).saturating_add(1), MAX - 1); + assert_eq!(3_usize.saturating_add(usize::MAX - 1), usize::MAX); + assert_eq!(usize::MAX.saturating_add(usize::MAX), usize::MAX); + assert_eq!((usize::MAX - 2).saturating_add(1), usize::MAX - 1); } #[test] fn test_saturating_sub_uint() { - use crate::usize::MAX; assert_eq!(5_usize.saturating_sub(3_usize), 2_usize); assert_eq!(3_usize.saturating_sub(5_usize), 0_usize); assert_eq!(0_usize.saturating_sub(1_usize), 0_usize); - assert_eq!((MAX - 1).saturating_sub(MAX), 0); + assert_eq!((usize::MAX - 1).saturating_sub(usize::MAX), 0); } #[test] fn test_saturating_add_int() { - use crate::isize::{MAX, MIN}; assert_eq!(3i32.saturating_add(5), 8); - assert_eq!(3isize.saturating_add(MAX - 1), MAX); - assert_eq!(MAX.saturating_add(MAX), MAX); - assert_eq!((MAX - 2).saturating_add(1), MAX - 1); + assert_eq!(3isize.saturating_add(isize::MAX - 1), isize::MAX); + assert_eq!(isize::MAX.saturating_add(isize::MAX), isize::MAX); + assert_eq!((isize::MAX - 2).saturating_add(1), isize::MAX - 1); assert_eq!(3i32.saturating_add(-5), -2); - assert_eq!(MIN.saturating_add(-1), MIN); - assert_eq!((-2isize).saturating_add(-MAX), MIN); + assert_eq!(isize::MIN.saturating_add(-1), isize::MIN); + assert_eq!((-2isize).saturating_add(-isize::MAX), isize::MIN); } #[test] fn test_saturating_sub_int() { - use crate::isize::{MAX, MIN}; assert_eq!(3i32.saturating_sub(5), -2); - assert_eq!(MIN.saturating_sub(1), MIN); - assert_eq!((-2isize).saturating_sub(MAX), MIN); + assert_eq!(isize::MIN.saturating_sub(1), isize::MIN); + assert_eq!((-2isize).saturating_sub(isize::MAX), isize::MIN); assert_eq!(3i32.saturating_sub(-5), 8); - assert_eq!(3isize.saturating_sub(-(MAX - 1)), MAX); - assert_eq!(MAX.saturating_sub(-MAX), MAX); - assert_eq!((MAX - 2).saturating_sub(-1), MAX - 1); + assert_eq!(3isize.saturating_sub(-(isize::MAX - 1)), isize::MAX); + assert_eq!(isize::MAX.saturating_sub(-isize::MAX), isize::MAX); + assert_eq!((isize::MAX - 2).saturating_sub(-1), isize::MAX - 1); } #[test] diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 77e521eae9afe..2250c0d4203ef 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -609,7 +609,6 @@ mod tests { use crate::sync::{Arc, Condvar, Mutex}; use crate::thread; use crate::time::Duration; - use crate::u64; #[test] fn smoke() { diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index e70204d6839fc..d6cc811154f11 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -2176,8 +2176,7 @@ mod tests { #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31 fn very_long_recv_timeout_wont_panic() { let (tx, rx) = channel::<()>(); - let join_handle = - thread::spawn(move || rx.recv_timeout(Duration::from_secs(u64::max_value()))); + let join_handle = thread::spawn(move || rx.recv_timeout(Duration::from_secs(u64::MAX))); thread::sleep(Duration::from_secs(1)); assert!(tx.send(()).is_ok()); assert_eq!(join_handle.join().unwrap(), Ok(())); diff --git a/src/libstd/sys/cloudabi/condvar.rs b/src/libstd/sys/cloudabi/condvar.rs index 3ba51d77494d4..dabdc0c9b510a 100644 --- a/src/libstd/sys/cloudabi/condvar.rs +++ b/src/libstd/sys/cloudabi/condvar.rs @@ -42,7 +42,7 @@ impl Condvar { let ret = abi::condvar_signal( condvar as *mut abi::condvar, abi::scope::PRIVATE, - abi::nthreads::max_value(), + abi::nthreads::MAX, ); assert_eq!(ret, abi::errno::SUCCESS, "Failed to broadcast on condition variable"); } diff --git a/src/libstd/sys/hermit/condvar.rs b/src/libstd/sys/hermit/condvar.rs index 94e3275448ae9..132e579b3a5cb 100644 --- a/src/libstd/sys/hermit/condvar.rs +++ b/src/libstd/sys/hermit/condvar.rs @@ -35,7 +35,7 @@ impl Condvar { pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool { let nanos = dur.as_nanos(); - let nanos = cmp::min(i64::max_value() as u128, nanos); + let nanos = cmp::min(i64::MAX as u128, nanos); // add current task to the wait queue let _ = abi::add_queue(self.id(), nanos as i64); diff --git a/src/libstd/sys/unix/android.rs b/src/libstd/sys/unix/android.rs index 8fc2599f0d762..ea05ee3d7cedf 100644 --- a/src/libstd/sys/unix/android.rs +++ b/src/libstd/sys/unix/android.rs @@ -95,7 +95,7 @@ pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> { match ftruncate64.get() { Some(f) => cvt_r(|| f(fd, size as i64)).map(drop), None => { - if size > i32::max_value() as u64 { + if size > i32::MAX as u64 { Err(io::Error::new(io::ErrorKind::InvalidInput, "cannot truncate >2GB")) } else { cvt_r(|| ftruncate(fd, size as i32)).map(drop) diff --git a/src/libstd/sys/unix/condvar.rs b/src/libstd/sys/unix/condvar.rs index b4896b7ad7476..9f1847943f326 100644 --- a/src/libstd/sys/unix/condvar.rs +++ b/src/libstd/sys/unix/condvar.rs @@ -10,14 +10,10 @@ unsafe impl Send for Condvar {} unsafe impl Sync for Condvar {} const TIMESPEC_MAX: libc::timespec = - libc::timespec { tv_sec: ::max_value(), tv_nsec: 1_000_000_000 - 1 }; + libc::timespec { tv_sec: ::MAX, tv_nsec: 1_000_000_000 - 1 }; fn saturating_cast_to_time_t(value: u64) -> libc::time_t { - if value > ::max_value() as u64 { - ::max_value() - } else { - value as libc::time_t - } + if value > ::MAX as u64 { ::MAX } else { value as libc::time_t } } impl Condvar { diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index 32c2ac43129bf..cd24605ec7ab7 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -1090,7 +1090,7 @@ impl<'a> Iterator for Incoming<'a> { } fn size_hint(&self) -> (usize, Option) { - (usize::max_value(), None) + (usize::MAX, None) } } diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs index 1ef7ffacfcf14..c481ca8961f86 100644 --- a/src/libstd/sys/unix/fd.rs +++ b/src/libstd/sys/unix/fd.rs @@ -23,11 +23,7 @@ fn max_len() -> usize { // intentionally showing odd behavior by rejecting any read with a size // larger than or equal to INT_MAX. To handle both of these the read // size is capped on both platforms. - if cfg!(target_os = "macos") { - ::max_value() as usize - 1 - } else { - ::max_value() as usize - } + if cfg!(target_os = "macos") { ::MAX as usize - 1 } else { ::MAX as usize } } impl FileDesc { @@ -58,7 +54,7 @@ impl FileDesc { libc::readv( self.fd, bufs.as_ptr() as *const libc::iovec, - cmp::min(bufs.len(), c_int::max_value() as usize) as c_int, + cmp::min(bufs.len(), c_int::MAX as usize) as c_int, ) })?; Ok(ret as usize) @@ -115,7 +111,7 @@ impl FileDesc { libc::writev( self.fd, bufs.as_ptr() as *const libc::iovec, - cmp::min(bufs.len(), c_int::max_value() as usize) as c_int, + cmp::min(bufs.len(), c_int::MAX as usize) as c_int, ) })?; Ok(ret as usize) diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 80cf6a5dbc27b..29cdbf05354fb 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -1196,7 +1196,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result { let mut written = 0u64; while written < len { let copy_result = if has_copy_file_range { - let bytes_to_copy = cmp::min(len - written, usize::max_value() as u64) as usize; + let bytes_to_copy = cmp::min(len - written, usize::MAX as u64) as usize; let copy_result = unsafe { // We actually don't have to adjust the offsets, // because copy_file_range adjusts the file offset automatically diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs index f062bc012f7ef..3717c660b575d 100644 --- a/src/libstd/sys/unix/net.rs +++ b/src/libstd/sys/unix/net.rs @@ -148,7 +148,7 @@ impl Socket { timeout = 1; } - let timeout = cmp::min(timeout, c_int::max_value() as u64) as c_int; + let timeout = cmp::min(timeout, c_int::MAX as u64) as c_int; match unsafe { libc::poll(&mut pollfd, 1, timeout) } { -1 => { @@ -283,8 +283,8 @@ impl Socket { )); } - let secs = if dur.as_secs() > libc::time_t::max_value() as u64 { - libc::time_t::max_value() + let secs = if dur.as_secs() > libc::time_t::MAX as u64 { + libc::time_t::MAX } else { dur.as_secs() as libc::time_t }; diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 895ea48e2b43e..7b3d69dcaa015 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -171,7 +171,7 @@ impl Thread { unsafe { while secs > 0 || nsecs > 0 { let mut ts = libc::timespec { - tv_sec: cmp::min(libc::time_t::max_value() as u64, secs) as libc::time_t, + tv_sec: cmp::min(libc::time_t::MAX as u64, secs) as libc::time_t, tv_nsec: nsecs, }; secs -= ts.tv_sec as u64; diff --git a/src/libstd/sys/vxworks/condvar.rs b/src/libstd/sys/vxworks/condvar.rs index f2a1d6815290d..5a77966d97468 100644 --- a/src/libstd/sys/vxworks/condvar.rs +++ b/src/libstd/sys/vxworks/condvar.rs @@ -10,14 +10,10 @@ unsafe impl Send for Condvar {} unsafe impl Sync for Condvar {} const TIMESPEC_MAX: libc::timespec = - libc::timespec { tv_sec: ::max_value(), tv_nsec: 1_000_000_000 - 1 }; + libc::timespec { tv_sec: ::MAX, tv_nsec: 1_000_000_000 - 1 }; fn saturating_cast_to_time_t(value: u64) -> libc::time_t { - if value > ::max_value() as u64 { - ::max_value() - } else { - value as libc::time_t - } + if value > ::MAX as u64 { ::MAX } else { value as libc::time_t } } impl Condvar { diff --git a/src/libstd/sys/vxworks/fd.rs b/src/libstd/sys/vxworks/fd.rs index 23e9dc428ce23..7fa86f0db043f 100644 --- a/src/libstd/sys/vxworks/fd.rs +++ b/src/libstd/sys/vxworks/fd.rs @@ -17,7 +17,7 @@ fn max_len() -> usize { // The maximum read limit on most posix-like systems is `SSIZE_MAX`, // with the man page quoting that if the count of bytes to read is // greater than `SSIZE_MAX` the result is "unspecified". - ::max_value() as usize + ::MAX as usize } impl FileDesc { @@ -48,7 +48,7 @@ impl FileDesc { libc::readv( self.fd, bufs.as_ptr() as *const libc::iovec, - cmp::min(bufs.len(), c_int::max_value() as usize) as c_int, + cmp::min(bufs.len(), c_int::MAX as usize) as c_int, ) })?; Ok(ret as usize) @@ -98,7 +98,7 @@ impl FileDesc { libc::writev( self.fd, bufs.as_ptr() as *const libc::iovec, - cmp::min(bufs.len(), c_int::max_value() as usize) as c_int, + cmp::min(bufs.len(), c_int::MAX as usize) as c_int, ) })?; Ok(ret as usize) diff --git a/src/libstd/sys/vxworks/net.rs b/src/libstd/sys/vxworks/net.rs index de0b15b43a2e2..32c27ab6e9e8d 100644 --- a/src/libstd/sys/vxworks/net.rs +++ b/src/libstd/sys/vxworks/net.rs @@ -107,7 +107,7 @@ impl Socket { timeout = 1; } - let timeout = cmp::min(timeout, c_int::max_value() as u64) as c_int; + let timeout = cmp::min(timeout, c_int::MAX as u64) as c_int; match unsafe { libc::poll(&mut pollfd, 1, timeout) } { -1 => { @@ -220,8 +220,8 @@ impl Socket { )); } - let secs = if dur.as_secs() > libc::time_t::max_value() as u64 { - libc::time_t::max_value() + let secs = if dur.as_secs() > libc::time_t::MAX as u64 { + libc::time_t::MAX } else { dur.as_secs() as libc::time_t }; diff --git a/src/libstd/sys/vxworks/thread.rs b/src/libstd/sys/vxworks/thread.rs index 4d0196e4b4de5..24a2e0f965d28 100644 --- a/src/libstd/sys/vxworks/thread.rs +++ b/src/libstd/sys/vxworks/thread.rs @@ -96,7 +96,7 @@ impl Thread { unsafe { while secs > 0 || nsecs > 0 { let mut ts = libc::timespec { - tv_sec: cmp::min(libc::time_t::max_value() as u64, secs) as libc::time_t, + tv_sec: cmp::min(libc::time_t::MAX as u64, secs) as libc::time_t, tv_nsec: nsecs, }; secs -= ts.tv_sec as u64; diff --git a/src/libstd/sys/wasi/mod.rs b/src/libstd/sys/wasi/mod.rs index 29fafaaa0b94f..4fe9661421b03 100644 --- a/src/libstd/sys/wasi/mod.rs +++ b/src/libstd/sys/wasi/mod.rs @@ -64,7 +64,7 @@ pub fn unsupported_err() -> std_io::Error { pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind { use std_io::ErrorKind::*; - if errno > u16::max_value() as i32 || errno < 0 { + if errno > u16::MAX as i32 || errno < 0 { return Other; } match errno as u16 { diff --git a/src/libstd/sys/wasi/thread.rs b/src/libstd/sys/wasi/thread.rs index 0986759b89b7c..0d39b1cec328c 100644 --- a/src/libstd/sys/wasi/thread.rs +++ b/src/libstd/sys/wasi/thread.rs @@ -25,7 +25,7 @@ impl Thread { pub fn sleep(dur: Duration) { let nanos = dur.as_nanos(); - assert!(nanos <= u64::max_value() as u128); + assert!(nanos <= u64::MAX as u128); const USERDATA: wasi::Userdata = 0x0123_45678; diff --git a/src/libstd/sys/wasm/condvar_atomics.rs b/src/libstd/sys/wasm/condvar_atomics.rs index a4021c0ee8380..1859cdd5a0ed8 100644 --- a/src/libstd/sys/wasm/condvar_atomics.rs +++ b/src/libstd/sys/wasm/condvar_atomics.rs @@ -48,7 +48,7 @@ impl Condvar { #[inline] pub unsafe fn notify_all(&self) { self.cnt.fetch_add(1, SeqCst); - wasm32::atomic_notify(self.ptr(), u32::max_value()); // -1 == "wake everyone" + wasm32::atomic_notify(self.ptr(), u32::MAX); // -1 == "wake everyone" } pub unsafe fn wait(&self, mutex: &Mutex) { @@ -72,7 +72,7 @@ impl Condvar { let ticket = self.cnt.load(SeqCst) as i32; mutex.unlock(); let nanos = dur.as_nanos(); - let nanos = cmp::min(i64::max_value() as u128, nanos); + let nanos = cmp::min(i64::MAX as u128, nanos); // If the return value is 2 then a timeout happened, so we return // `false` as we weren't actually notified. diff --git a/src/libstd/sys/wasm/thread.rs b/src/libstd/sys/wasm/thread.rs index 0e0e78a827670..0a11896a0048f 100644 --- a/src/libstd/sys/wasm/thread.rs +++ b/src/libstd/sys/wasm/thread.rs @@ -38,7 +38,7 @@ impl Thread { // 2). let mut nanos = dur.as_nanos(); while nanos > 0 { - let amt = cmp::min(i64::max_value() as u128, nanos); + let amt = cmp::min(i64::MAX as u128, nanos); let mut x = 0; let val = unsafe { wasm32::i32_atomic_wait(&mut x, 0, amt as i64) }; debug_assert_eq!(val, 2); diff --git a/src/libstd/sys/windows/handle.rs b/src/libstd/sys/windows/handle.rs index 2131cfc2c94bc..0d4baa3b340df 100644 --- a/src/libstd/sys/windows/handle.rs +++ b/src/libstd/sys/windows/handle.rs @@ -70,7 +70,7 @@ impl RawHandle { pub fn read(&self, buf: &mut [u8]) -> io::Result { let mut read = 0; - let len = cmp::min(buf.len(), ::max_value() as usize) as c::DWORD; + let len = cmp::min(buf.len(), ::MAX as usize) as c::DWORD; let res = cvt(unsafe { c::ReadFile(self.0, buf.as_mut_ptr() as c::LPVOID, len, &mut read, ptr::null_mut()) }); @@ -99,7 +99,7 @@ impl RawHandle { pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { let mut read = 0; - let len = cmp::min(buf.len(), ::max_value() as usize) as c::DWORD; + let len = cmp::min(buf.len(), ::MAX as usize) as c::DWORD; let res = unsafe { let mut overlapped: c::OVERLAPPED = mem::zeroed(); overlapped.Offset = offset as u32; @@ -118,7 +118,7 @@ impl RawHandle { buf: &mut [u8], overlapped: *mut c::OVERLAPPED, ) -> io::Result> { - let len = cmp::min(buf.len(), ::max_value() as usize) as c::DWORD; + let len = cmp::min(buf.len(), ::MAX as usize) as c::DWORD; let mut amt = 0; let res = cvt(c::ReadFile(self.0, buf.as_ptr() as c::LPVOID, len, &mut amt, overlapped)); match res { @@ -165,7 +165,7 @@ impl RawHandle { pub fn write(&self, buf: &[u8]) -> io::Result { let mut amt = 0; - let len = cmp::min(buf.len(), ::max_value() as usize) as c::DWORD; + let len = cmp::min(buf.len(), ::MAX as usize) as c::DWORD; cvt(unsafe { c::WriteFile(self.0, buf.as_ptr() as c::LPVOID, len, &mut amt, ptr::null_mut()) })?; @@ -183,7 +183,7 @@ impl RawHandle { pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { let mut written = 0; - let len = cmp::min(buf.len(), ::max_value() as usize) as c::DWORD; + let len = cmp::min(buf.len(), ::MAX as usize) as c::DWORD; unsafe { let mut overlapped: c::OVERLAPPED = mem::zeroed(); overlapped.Offset = offset as u32; diff --git a/src/libstd/sys/windows/io.rs b/src/libstd/sys/windows/io.rs index 5525d2832526f..fb06df1f80cda 100644 --- a/src/libstd/sys/windows/io.rs +++ b/src/libstd/sys/windows/io.rs @@ -12,7 +12,7 @@ pub struct IoSlice<'a> { impl<'a> IoSlice<'a> { #[inline] pub fn new(buf: &'a [u8]) -> IoSlice<'a> { - assert!(buf.len() <= c::ULONG::max_value() as usize); + assert!(buf.len() <= c::ULONG::MAX as usize); IoSlice { vec: c::WSABUF { len: buf.len() as c::ULONG, @@ -49,7 +49,7 @@ pub struct IoSliceMut<'a> { impl<'a> IoSliceMut<'a> { #[inline] pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { - assert!(buf.len() <= c::ULONG::max_value() as usize); + assert!(buf.len() <= c::ULONG::MAX as usize); IoSliceMut { vec: c::WSABUF { len: buf.len() as c::ULONG, buf: buf.as_mut_ptr() as *mut c::CHAR }, _p: PhantomData, diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index 4098c6b3ee937..2ad1de6ae9f0a 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -295,7 +295,7 @@ pub fn dur2timeout(dur: Duration) -> c::DWORD { .checked_mul(1000) .and_then(|ms| ms.checked_add((dur.subsec_nanos() as u64) / 1_000_000)) .and_then(|ms| ms.checked_add(if dur.subsec_nanos() % 1_000_000 > 0 { 1 } else { 0 })) - .map(|ms| if ms > ::max_value() as u64 { c::INFINITE } else { ms as c::DWORD }) + .map(|ms| if ms > ::MAX as u64 { c::INFINITE } else { ms as c::DWORD }) .unwrap_or(c::INFINITE) } diff --git a/src/libstd/sys/windows/net.rs b/src/libstd/sys/windows/net.rs index a15ded92f08c4..9e74454bc2335 100644 --- a/src/libstd/sys/windows/net.rs +++ b/src/libstd/sys/windows/net.rs @@ -228,7 +228,7 @@ impl Socket { fn recv_with_flags(&self, buf: &mut [u8], flags: c_int) -> io::Result { // On unix when a socket is shut down all further reads return 0, so we // do the same on windows to map a shut down socket to returning EOF. - let len = cmp::min(buf.len(), i32::max_value() as usize) as i32; + let len = cmp::min(buf.len(), i32::MAX as usize) as i32; unsafe { match c::recv(self.0, buf.as_mut_ptr() as *mut c_void, len, flags) { -1 if c::WSAGetLastError() == c::WSAESHUTDOWN => Ok(0), @@ -245,7 +245,7 @@ impl Socket { pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { // On unix when a socket is shut down all further reads return 0, so we // do the same on windows to map a shut down socket to returning EOF. - let len = cmp::min(bufs.len(), c::DWORD::max_value() as usize) as c::DWORD; + let len = cmp::min(bufs.len(), c::DWORD::MAX as usize) as c::DWORD; let mut nread = 0; let mut flags = 0; unsafe { @@ -282,7 +282,7 @@ impl Socket { ) -> io::Result<(usize, SocketAddr)> { let mut storage: c::SOCKADDR_STORAGE_LH = unsafe { mem::zeroed() }; let mut addrlen = mem::size_of_val(&storage) as c::socklen_t; - let len = cmp::min(buf.len(), ::max_value() as usize) as wrlen_t; + let len = cmp::min(buf.len(), ::MAX as usize) as wrlen_t; // On unix when a socket is shut down all further reads return 0, so we // do the same on windows to map a shut down socket to returning EOF. @@ -313,7 +313,7 @@ impl Socket { } pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { - let len = cmp::min(bufs.len(), c::DWORD::max_value() as usize) as c::DWORD; + let len = cmp::min(bufs.len(), c::DWORD::MAX as usize) as c::DWORD; let mut nwritten = 0; unsafe { cvt(c::WSASend( diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index 1c03bc9234448..81a5ef95e82dc 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -271,7 +271,7 @@ impl TcpStream { } pub fn write(&self, buf: &[u8]) -> io::Result { - let len = cmp::min(buf.len(), ::max_value() as usize) as wrlen_t; + let len = cmp::min(buf.len(), ::MAX as usize) as wrlen_t; let ret = cvt(unsafe { c::send(*self.inner.as_inner(), buf.as_ptr() as *const c_void, len, MSG_NOSIGNAL) })?; @@ -502,7 +502,7 @@ impl UdpSocket { } pub fn send_to(&self, buf: &[u8], dst: &SocketAddr) -> io::Result { - let len = cmp::min(buf.len(), ::max_value() as usize) as wrlen_t; + let len = cmp::min(buf.len(), ::MAX as usize) as wrlen_t; let (dstp, dstlen) = dst.into_inner(); let ret = cvt(unsafe { c::sendto( @@ -641,7 +641,7 @@ impl UdpSocket { } pub fn send(&self, buf: &[u8]) -> io::Result { - let len = cmp::min(buf.len(), ::max_value() as usize) as wrlen_t; + let len = cmp::min(buf.len(), ::MAX as usize) as wrlen_t; let ret = cvt(unsafe { c::send(*self.inner.as_inner(), buf.as_ptr() as *const c_void, len, MSG_NOSIGNAL) })?; diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 3134a5967566b..d435ca6842518 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -1530,7 +1530,6 @@ mod tests { use crate::sync::mpsc::{channel, Sender}; use crate::thread::{self, ThreadId}; use crate::time::Duration; - use crate::u32; // !!! These tests are dangerous. If something is buggy, they will hang, !!! // !!! instead of exiting cleanly. This might wedge the buildbots. !!! diff --git a/src/libstd/time.rs b/src/libstd/time.rs index c36e78b1d004e..bc3bfde6d7559 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -686,7 +686,7 @@ mod tests { // checked_add_duration will not panic on overflow let mut maybe_t = Some(Instant::now()); - let max_duration = Duration::from_secs(u64::max_value()); + let max_duration = Duration::from_secs(u64::MAX); // in case `Instant` can store `>= now + max_duration`. for _ in 0..2 { maybe_t = maybe_t.and_then(|t| t.checked_add(max_duration)); @@ -766,7 +766,7 @@ mod tests { // checked_add_duration will not panic on overflow let mut maybe_t = Some(SystemTime::UNIX_EPOCH); - let max_duration = Duration::from_secs(u64::max_value()); + let max_duration = Duration::from_secs(u64::MAX); // in case `SystemTime` can store `>= UNIX_EPOCH + max_duration`. for _ in 0..2 { maybe_t = maybe_t.and_then(|t| t.checked_add(max_duration)); diff --git a/src/test/rustdoc/show-const-contents.rs b/src/test/rustdoc/show-const-contents.rs index b35f67ef91243..814339e198f95 100644 --- a/src/test/rustdoc/show-const-contents.rs +++ b/src/test/rustdoc/show-const-contents.rs @@ -28,8 +28,8 @@ pub const CONST_CALC_I32: i32 = 42 + 1; // @!has show_const_contents/constant.CONST_REF_I32.html '; //' pub const CONST_REF_I32: &'static i32 = &42; -// @has show_const_contents/constant.CONST_I32_MAX.html '= i32::max_value(); // 2_147_483_647i32' -pub const CONST_I32_MAX: i32 = i32::max_value(); +// @has show_const_contents/constant.CONST_I32_MAX.html '= i32::MAX; // 2_147_483_647i32' +pub const CONST_I32_MAX: i32 = i32::MAX; // @!has show_const_contents/constant.UNIT.html '= ();' // @!has show_const_contents/constant.UNIT.html '; //' @@ -56,11 +56,11 @@ pub use std::i32::MAX; macro_rules! int_module { ($T:ident) => ( - pub const MIN: $T = $T::min_value(); + pub const MIN: $T = $T::MIN; ) } -// @has show_const_contents/constant.MIN.html '= i16::min_value(); // -32_768i16' +// @has show_const_contents/constant.MIN.html '= i16::MIN; // -32_768i16' int_module!(i16); // @has show_const_contents/constant.ESCAPE.html //pre '= r#""#;' diff --git a/src/test/ui/consts/const-eval/shift_overflow.rs b/src/test/ui/consts/const-eval/shift_overflow.rs index f7d0f6bd96144..e843584b69bb5 100644 --- a/src/test/ui/consts/const-eval/shift_overflow.rs +++ b/src/test/ui/consts/const-eval/shift_overflow.rs @@ -1,6 +1,6 @@ enum Foo { // test that we detect overflows for non-u32 discriminants - X = 1 << ((u32::max_value() as u64) + 1), //~ ERROR E0080 + X = 1 << ((u32::MAX as u64) + 1), //~ ERROR E0080 Y = 42, } diff --git a/src/test/ui/consts/const-eval/shift_overflow.stderr b/src/test/ui/consts/const-eval/shift_overflow.stderr index 5db231cd5b0df..f4840e9ac96bd 100644 --- a/src/test/ui/consts/const-eval/shift_overflow.stderr +++ b/src/test/ui/consts/const-eval/shift_overflow.stderr @@ -1,8 +1,8 @@ error[E0080]: evaluation of constant value failed --> $DIR/shift_overflow.rs:3:9 | -LL | X = 1 << ((u32::max_value() as u64) + 1), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to shift left with overflow +LL | X = 1 << ((u32::MAX as u64) + 1), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to shift left with overflow error: aborting due to previous error diff --git a/src/test/ui/consts/const-int-arithmetic.rs b/src/test/ui/consts/const-int-arithmetic.rs index ab24abeba32fe..9c94551f7440e 100644 --- a/src/test/ui/consts/const-int-arithmetic.rs +++ b/src/test/ui/consts/const-int-arithmetic.rs @@ -34,8 +34,8 @@ suite!( C6: 5i8.checked_mul(122), None; C7: (-127i8).checked_mul(-99), None; - C8: (i8::min_value() + 1).checked_div(-1), Some(127); - C9: i8::min_value().checked_div(-1), None; + C8: (i8::MIN + 1).checked_div(-1), Some(127); + C9: i8::MIN.checked_div(-1), None; C10: 1i8.checked_div(0), None; C11: 5i8.checked_rem(2), Some(1); @@ -56,8 +56,8 @@ suite!( C21: i8::MIN.checked_abs(), None; // `const_euclidean_int_methods` - C22: (i8::min_value() + 1).checked_div_euclid(-1), Some(127); - C23: i8::min_value().checked_div_euclid(-1), None; + C22: (i8::MIN + 1).checked_div_euclid(-1), Some(127); + C23: i8::MIN.checked_div_euclid(-1), None; C24: (1i8).checked_div_euclid(0), None; C25: 5i8.checked_rem_euclid(2), Some(1); @@ -72,12 +72,12 @@ suite!( saturating_and_wrapping -> i8 { // `const_saturating_int_methods` C28: 100i8.saturating_add(1), 101; - C29: i8::max_value().saturating_add(100), i8::max_value(); - C30: i8::min_value().saturating_add(-1), i8::min_value(); + C29: i8::MAX.saturating_add(100), i8::MAX; + C30: i8::MIN.saturating_add(-1), i8::MIN; C31: 100i8.saturating_sub(127), -27; - C32: i8::min_value().saturating_sub(100), i8::min_value(); - C33: i8::max_value().saturating_sub(-1), i8::max_value(); + C32: i8::MIN.saturating_sub(100), i8::MIN; + C33: i8::MAX.saturating_sub(-1), i8::MAX; C34: 10i8.saturating_mul(12), 120; C35: i8::MAX.saturating_mul(10), i8::MAX; @@ -85,13 +85,13 @@ suite!( C37: 100i8.saturating_neg(), -100; C38: (-100i8).saturating_neg(), 100; - C39: i8::min_value().saturating_neg(), i8::max_value(); - C40: i8::max_value().saturating_neg(), i8::min_value() + 1; + C39: i8::MIN.saturating_neg(), i8::MAX; + C40: i8::MAX.saturating_neg(), i8::MIN + 1; C57: 100i8.saturating_abs(), 100; C58: (-100i8).saturating_abs(), 100; - C59: i8::min_value().saturating_abs(), i8::max_value(); - C60: (i8::min_value() + 1).saturating_abs(), i8::max_value(); + C59: i8::MIN.saturating_abs(), i8::MAX; + C60: (i8::MIN + 1).saturating_abs(), i8::MAX; // `const_wrapping_int_methods` C41: 100i8.wrapping_div(10), 10; diff --git a/src/test/ui/consts/const-int-conversion-rpass.rs b/src/test/ui/consts/const-int-conversion-rpass.rs index 6484169dd9ae1..4aaeeaa38853d 100644 --- a/src/test/ui/consts/const-int-conversion-rpass.rs +++ b/src/test/ui/consts/const-int-conversion-rpass.rs @@ -6,13 +6,13 @@ const FROM_LE_BYTES: i32 = i32::from_le_bytes([0x12, 0x34, 0x56, 0x78]); const FROM_NE_BYTES: i32 = i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0])); const TO_BE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_be_bytes(); const TO_LE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_le_bytes(); -const TO_NE_BYTES: [u8; 4] = i32::min_value().to_be().to_ne_bytes(); +const TO_NE_BYTES: [u8; 4] = i32::MIN.to_be().to_ne_bytes(); fn main() { assert_eq!(REVERSE, 0x1e6a2c48); assert_eq!(FROM_BE_BYTES, 0x12_34_56_78); assert_eq!(FROM_LE_BYTES, 0x78_56_34_12); - assert_eq!(FROM_NE_BYTES, i32::min_value()); + assert_eq!(FROM_NE_BYTES, i32::MIN); assert_eq!(TO_BE_BYTES, [0x12, 0x34, 0x56, 0x78]); assert_eq!(TO_LE_BYTES, [0x78, 0x56, 0x34, 0x12]); assert_eq!(TO_NE_BYTES, [0x80, 0, 0, 0]); diff --git a/src/test/ui/consts/const-int-conversion.rs b/src/test/ui/consts/const-int-conversion.rs index b80e616eae77e..5a05a2b35937a 100644 --- a/src/test/ui/consts/const-int-conversion.rs +++ b/src/test/ui/consts/const-int-conversion.rs @@ -11,6 +11,6 @@ fn main() { //~^ ERROR temporary value dropped while borrowed let c: &'static [u8] = &(0x12_34_56_78_i32.to_le_bytes()); //~^ ERROR temporary value dropped while borrowed - let d: &'static [u8] = &(i32::min_value().to_be().to_ne_bytes()); + let d: &'static [u8] = &(i32::MIN.to_be().to_ne_bytes()); //~^ ERROR temporary value dropped while borrowed } diff --git a/src/test/ui/consts/const-int-conversion.stderr b/src/test/ui/consts/const-int-conversion.stderr index 237f9627219bd..61162a792262b 100644 --- a/src/test/ui/consts/const-int-conversion.stderr +++ b/src/test/ui/consts/const-int-conversion.stderr @@ -67,8 +67,8 @@ LL | } error[E0716]: temporary value dropped while borrowed --> $DIR/const-int-conversion.rs:14:29 | -LL | let d: &'static [u8] = &(i32::min_value().to_be().to_ne_bytes()); - | ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use +LL | let d: &'static [u8] = &(i32::MIN.to_be().to_ne_bytes()); + | ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use | | | type annotation requires that borrow lasts for `'static` LL | diff --git a/src/test/ui/consts/const-int-overflowing-rpass.rs b/src/test/ui/consts/const-int-overflowing-rpass.rs index 9be87a6447cda..eecb88becabca 100644 --- a/src/test/ui/consts/const-int-overflowing-rpass.rs +++ b/src/test/ui/consts/const-int-overflowing-rpass.rs @@ -1,7 +1,7 @@ // run-pass const ADD_A: (u32, bool) = 5u32.overflowing_add(2); -const ADD_B: (u32, bool) = u32::max_value().overflowing_add(1); +const ADD_B: (u32, bool) = u32::MAX.overflowing_add(1); const SUB_A: (u32, bool) = 5u32.overflowing_sub(2); const SUB_B: (u32, bool) = 0u32.overflowing_sub(1); @@ -20,14 +20,14 @@ const NEG_B: (u32, bool) = core::u32::MAX.overflowing_neg(); const ABS_POS: (i32, bool) = 10i32.overflowing_abs(); const ABS_NEG: (i32, bool) = (-10i32).overflowing_abs(); -const ABS_MIN: (i32, bool) = i32::min_value().overflowing_abs(); +const ABS_MIN: (i32, bool) = i32::MIN.overflowing_abs(); fn main() { assert_eq!(ADD_A, (7, false)); assert_eq!(ADD_B, (0, true)); assert_eq!(SUB_A, (3, false)); - assert_eq!(SUB_B, (u32::max_value(), true)); + assert_eq!(SUB_B, (u32::MAX, true)); assert_eq!(MUL_A, (10, false)); assert_eq!(MUL_B, (1410065408, true)); @@ -43,5 +43,5 @@ fn main() { assert_eq!(ABS_POS, (10, false)); assert_eq!(ABS_NEG, (10, false)); - assert_eq!(ABS_MIN, (i32::min_value(), true)); + assert_eq!(ABS_MIN, (i32::MIN, true)); } diff --git a/src/test/ui/consts/const-int-pow-rpass.rs b/src/test/ui/consts/const-int-pow-rpass.rs index b0fba19455ba8..4f936236dbb20 100644 --- a/src/test/ui/consts/const-int-pow-rpass.rs +++ b/src/test/ui/consts/const-int-pow-rpass.rs @@ -20,10 +20,10 @@ const NEXT_POWER_OF_TWO: u32 = 3u32.next_power_of_two(); const CHECKED_NEXT_POWER_OF_TWO_OK: Option = 3u32.checked_next_power_of_two(); const CHECKED_NEXT_POWER_OF_TWO_OVERFLOW: Option = - u32::max_value().checked_next_power_of_two(); + u32::MAX.checked_next_power_of_two(); const WRAPPING_NEXT_POWER_OF_TWO: u32 = - u32::max_value().wrapping_next_power_of_two(); + u32::MAX.wrapping_next_power_of_two(); fn main() { assert!(!IS_POWER_OF_TWO_A); @@ -37,7 +37,7 @@ fn main() { assert_eq!(WRAPPING_POW, 217); assert_eq!(OVERFLOWING_POW, (217, true)); - assert_eq!(SATURATING_POW, u8::max_value()); + assert_eq!(SATURATING_POW, u8::MAX); assert_eq!(NEXT_POWER_OF_TWO, 4); diff --git a/src/test/ui/consts/const-int-saturating-arith.rs b/src/test/ui/consts/const-int-saturating-arith.rs index d0a3eccd17763..4718120a51bd3 100644 --- a/src/test/ui/consts/const-int-saturating-arith.rs +++ b/src/test/ui/consts/const-int-saturating-arith.rs @@ -2,33 +2,33 @@ #![feature(const_saturating_int_methods)] const INT_U32_NO: u32 = (42 as u32).saturating_add(2); -const INT_U32: u32 = u32::max_value().saturating_add(1); -const INT_U128: u128 = u128::max_value().saturating_add(1); -const INT_I128: i128 = i128::max_value().saturating_add(1); -const INT_I128_NEG: i128 = i128::min_value().saturating_add(-1); +const INT_U32: u32 = u32::MAX.saturating_add(1); +const INT_U128: u128 = u128::MAX.saturating_add(1); +const INT_I128: i128 = i128::MAX.saturating_add(1); +const INT_I128_NEG: i128 = i128::MIN.saturating_add(-1); const INT_U32_NO_SUB: u32 = (42 as u32).saturating_sub(2); const INT_U32_SUB: u32 = (1 as u32).saturating_sub(2); const INT_I32_NO_SUB: i32 = (-42 as i32).saturating_sub(2); -const INT_I32_NEG_SUB: i32 = i32::min_value().saturating_sub(1); -const INT_I32_POS_SUB: i32 = i32::max_value().saturating_sub(-1); +const INT_I32_NEG_SUB: i32 = i32::MIN.saturating_sub(1); +const INT_I32_POS_SUB: i32 = i32::MAX.saturating_sub(-1); const INT_U128_SUB: u128 = (0 as u128).saturating_sub(1); -const INT_I128_NEG_SUB: i128 = i128::min_value().saturating_sub(1); -const INT_I128_POS_SUB: i128 = i128::max_value().saturating_sub(-1); +const INT_I128_NEG_SUB: i128 = i128::MIN.saturating_sub(1); +const INT_I128_POS_SUB: i128 = i128::MAX.saturating_sub(-1); fn main() { assert_eq!(INT_U32_NO, 44); - assert_eq!(INT_U32, u32::max_value()); - assert_eq!(INT_U128, u128::max_value()); - assert_eq!(INT_I128, i128::max_value()); - assert_eq!(INT_I128_NEG, i128::min_value()); + assert_eq!(INT_U32, u32::MAX); + assert_eq!(INT_U128, u128::MAX); + assert_eq!(INT_I128, i128::MAX); + assert_eq!(INT_I128_NEG, i128::MIN); assert_eq!(INT_U32_NO_SUB, 40); assert_eq!(INT_U32_SUB, 0); assert_eq!(INT_I32_NO_SUB, -44); - assert_eq!(INT_I32_NEG_SUB, i32::min_value()); - assert_eq!(INT_I32_POS_SUB, i32::max_value()); + assert_eq!(INT_I32_NEG_SUB, i32::MIN); + assert_eq!(INT_I32_POS_SUB, i32::MAX); assert_eq!(INT_U128_SUB, 0); - assert_eq!(INT_I128_NEG_SUB, i128::min_value()); - assert_eq!(INT_I128_POS_SUB, i128::max_value()); + assert_eq!(INT_I128_NEG_SUB, i128::MIN); + assert_eq!(INT_I128_POS_SUB, i128::MAX); } diff --git a/src/test/ui/consts/const-int-unchecked.rs b/src/test/ui/consts/const-int-unchecked.rs index fb09f62854d61..1596093b2c14b 100644 --- a/src/test/ui/consts/const-int-unchecked.rs +++ b/src/test/ui/consts/const-int-unchecked.rs @@ -131,12 +131,12 @@ const _: u16 = unsafe { std::intrinsics::unchecked_mul(300u16, 250u16) }; const _: i32 = unsafe { std::intrinsics::unchecked_div(1, 0) }; //~^ ERROR any use of this value will cause an error -const _: i32 = unsafe { std::intrinsics::unchecked_div(i32::min_value(), -1) }; +const _: i32 = unsafe { std::intrinsics::unchecked_div(i32::MIN, -1) }; //~^ ERROR any use of this value will cause an error const _: i32 = unsafe { std::intrinsics::unchecked_rem(1, 0) }; //~^ ERROR any use of this value will cause an error -const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::min_value(), -1) }; +const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::MIN, -1) }; //~^ ERROR any use of this value will cause an error fn main() {} diff --git a/src/test/ui/consts/const-int-unchecked.stderr b/src/test/ui/consts/const-int-unchecked.stderr index cf70454b6bf9e..0287b404e7d46 100644 --- a/src/test/ui/consts/const-int-unchecked.stderr +++ b/src/test/ui/consts/const-int-unchecked.stderr @@ -355,8 +355,8 @@ LL | const _: i32 = unsafe { std::intrinsics::unchecked_div(1, 0) }; error: any use of this value will cause an error --> $DIR/const-int-unchecked.rs:134:25 | -LL | const _: i32 = unsafe { std::intrinsics::unchecked_div(i32::min_value(), -1) }; - | ------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--- +LL | const _: i32 = unsafe { std::intrinsics::unchecked_div(i32::MIN, -1) }; + | ------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--- | | | overflow executing `unchecked_div` @@ -371,8 +371,8 @@ LL | const _: i32 = unsafe { std::intrinsics::unchecked_rem(1, 0) }; error: any use of this value will cause an error --> $DIR/const-int-unchecked.rs:139:25 | -LL | const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::min_value(), -1) }; - | ------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--- +LL | const _: i32 = unsafe { std::intrinsics::unchecked_rem(i32::MIN, -1) }; + | ------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--- | | | overflow executing `unchecked_rem` diff --git a/src/test/ui/consts/const-int-wrapping-rpass.rs b/src/test/ui/consts/const-int-wrapping-rpass.rs index 2bbad99a52a90..225d1e9393db4 100644 --- a/src/test/ui/consts/const-int-wrapping-rpass.rs +++ b/src/test/ui/consts/const-int-wrapping-rpass.rs @@ -1,10 +1,10 @@ // run-pass const ADD_A: u32 = 200u32.wrapping_add(55); -const ADD_B: u32 = 200u32.wrapping_add(u32::max_value()); +const ADD_B: u32 = 200u32.wrapping_add(u32::MAX); const SUB_A: u32 = 100u32.wrapping_sub(100); -const SUB_B: u32 = 100u32.wrapping_sub(u32::max_value()); +const SUB_B: u32 = 100u32.wrapping_sub(u32::MAX); const MUL_A: u8 = 10u8.wrapping_mul(12); const MUL_B: u8 = 25u8.wrapping_mul(12); @@ -20,7 +20,7 @@ const NEG_B: u32 = 1234567890u32.wrapping_neg(); const ABS_POS: i32 = 10i32.wrapping_abs(); const ABS_NEG: i32 = (-10i32).wrapping_abs(); -const ABS_MIN: i32 = i32::min_value().wrapping_abs(); +const ABS_MIN: i32 = i32::MIN.wrapping_abs(); fn main() { assert_eq!(ADD_A, 255); @@ -43,5 +43,5 @@ fn main() { assert_eq!(ABS_POS, 10); assert_eq!(ABS_NEG, 10); - assert_eq!(ABS_MIN, i32::min_value()); + assert_eq!(ABS_MIN, i32::MIN); } diff --git a/src/test/ui/enum-discriminant/issue-70509-partial_eq.rs b/src/test/ui/enum-discriminant/issue-70509-partial_eq.rs index e9c6104e3875a..4e2cc89948a01 100644 --- a/src/test/ui/enum-discriminant/issue-70509-partial_eq.rs +++ b/src/test/ui/enum-discriminant/issue-70509-partial_eq.rs @@ -5,7 +5,7 @@ #[repr(i128)] enum Test { A(Box) = 0, - B(usize) = u64::max_value() as i128 + 1, + B(usize) = u64::MAX as i128 + 1, } fn main() { diff --git a/src/test/ui/enum-discriminant/repr128.rs b/src/test/ui/enum-discriminant/repr128.rs index 420b6007c6d85..eefbc44f585b2 100644 --- a/src/test/ui/enum-discriminant/repr128.rs +++ b/src/test/ui/enum-discriminant/repr128.rs @@ -8,9 +8,9 @@ use std::marker::DiscriminantKind; enum Signed { Zero = 0, Staircase = 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f, - U64Limit = u64::max_value() as i128 + 1, + U64Limit = u64::MAX as i128 + 1, SmallNegative = -1, - BigNegative = i128::min_value(), + BigNegative = i128::MIN, Next, } @@ -18,7 +18,7 @@ enum Signed { enum Unsigned { Zero = 0, Staircase = 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f, - U64Limit = u64::max_value() as u128 + 1, + U64Limit = u64::MAX as u128 + 1, Next, } @@ -32,13 +32,13 @@ where fn main() { discr(Signed::Zero, 0); discr(Signed::Staircase, 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f); - discr(Signed::U64Limit, u64::max_value() as i128 + 1); + discr(Signed::U64Limit, u64::MAX as i128 + 1); discr(Signed::SmallNegative, -1); - discr(Signed::BigNegative, i128::min_value()); - discr(Signed::Next, i128::min_value() + 1); + discr(Signed::BigNegative, i128::MIN); + discr(Signed::Next, i128::MIN + 1); discr(Unsigned::Zero, 0); discr(Unsigned::Staircase, 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f); - discr(Unsigned::U64Limit, u64::max_value() as u128 + 1); - discr(Unsigned::Next, u64::max_value() as u128 + 2); + discr(Unsigned::U64Limit, u64::MAX as u128 + 1); + discr(Unsigned::Next, u64::MAX as u128 + 2); } diff --git a/src/test/ui/issues/issue-44216-add-instant.rs b/src/test/ui/issues/issue-44216-add-instant.rs index c2f3598f645bb..78cfecf2f32f0 100644 --- a/src/test/ui/issues/issue-44216-add-instant.rs +++ b/src/test/ui/issues/issue-44216-add-instant.rs @@ -6,5 +6,5 @@ use std::time::{Instant, Duration}; fn main() { let now = Instant::now(); - let _ = now + Duration::from_secs(u64::max_value()); + let _ = now + Duration::from_secs(u64::MAX); } diff --git a/src/test/ui/issues/issue-44216-add-system-time.rs b/src/test/ui/issues/issue-44216-add-system-time.rs index 9a88cb7c18916..7e9a3f802ec89 100644 --- a/src/test/ui/issues/issue-44216-add-system-time.rs +++ b/src/test/ui/issues/issue-44216-add-system-time.rs @@ -6,5 +6,5 @@ use std::time::{Duration, SystemTime}; fn main() { let now = SystemTime::now(); - let _ = now + Duration::from_secs(u64::max_value()); + let _ = now + Duration::from_secs(u64::MAX); } diff --git a/src/test/ui/issues/issue-44216-sub-instant.rs b/src/test/ui/issues/issue-44216-sub-instant.rs index 2decd88bbc06b..e40f80d449d96 100644 --- a/src/test/ui/issues/issue-44216-sub-instant.rs +++ b/src/test/ui/issues/issue-44216-sub-instant.rs @@ -6,5 +6,5 @@ use std::time::{Instant, Duration}; fn main() { let now = Instant::now(); - let _ = now - Duration::from_secs(u64::max_value()); + let _ = now - Duration::from_secs(u64::MAX); } diff --git a/src/test/ui/issues/issue-44216-sub-system-time.rs b/src/test/ui/issues/issue-44216-sub-system-time.rs index e58a31a41a5e9..2c5a000fab692 100644 --- a/src/test/ui/issues/issue-44216-sub-system-time.rs +++ b/src/test/ui/issues/issue-44216-sub-system-time.rs @@ -6,5 +6,5 @@ use std::time::{Duration, SystemTime}; fn main() { let now = SystemTime::now(); - let _ = now - Duration::from_secs(u64::max_value()); + let _ = now - Duration::from_secs(u64::MAX); } diff --git a/src/test/ui/issues/issue-8460.rs b/src/test/ui/issues/issue-8460.rs index 3fd576a8d3580..a7de4bd74aae4 100644 --- a/src/test/ui/issues/issue-8460.rs +++ b/src/test/ui/issues/issue-8460.rs @@ -27,21 +27,21 @@ macro_rules! check { fn main() { check![ - isize::min_value() / -isize::one(), - i8::min_value() / -i8::one(), - i16::min_value() / -i16::one(), - i32::min_value() / -i32::one(), - i64::min_value() / -i64::one(), + isize::MIN / -isize::one(), + i8::MIN / -i8::one(), + i16::MIN / -i16::one(), + i32::MIN / -i32::one(), + i64::MIN / -i64::one(), 1isize / isize::zero(), 1i8 / i8::zero(), 1i16 / i16::zero(), 1i32 / i32::zero(), 1i64 / i64::zero(), - isize::min_value() % -isize::one(), - i8::min_value() % -i8::one(), - i16::min_value() % -i16::one(), - i32::min_value() % -i32::one(), - i64::min_value() % -i64::one(), + isize::MIN % -isize::one(), + i8::MIN % -i8::one(), + i16::MIN % -i16::one(), + i32::MIN % -i32::one(), + i64::MIN % -i64::one(), 1isize % isize::zero(), 1i8 % i8::zero(), 1i16 % i16::zero(), diff --git a/src/test/ui/iterators/iter-step-overflow-debug.rs b/src/test/ui/iterators/iter-step-overflow-debug.rs index 5d67c7cbb4256..67605d2fcc253 100644 --- a/src/test/ui/iterators/iter-step-overflow-debug.rs +++ b/src/test/ui/iterators/iter-step-overflow-debug.rs @@ -6,14 +6,14 @@ use std::panic; fn main() { let r = panic::catch_unwind(|| { - let mut it = u8::max_value()..; + let mut it = u8::MAX..; it.next().unwrap(); // 255 it.next().unwrap(); }); assert!(r.is_err()); let r = panic::catch_unwind(|| { - let mut it = i8::max_value()..; + let mut it = i8::MAX..; it.next().unwrap(); // 127 it.next().unwrap(); }); diff --git a/src/test/ui/iterators/iter-step-overflow-ndebug.rs b/src/test/ui/iterators/iter-step-overflow-ndebug.rs index a0ad92071b66c..33e708769badb 100644 --- a/src/test/ui/iterators/iter-step-overflow-ndebug.rs +++ b/src/test/ui/iterators/iter-step-overflow-ndebug.rs @@ -2,11 +2,11 @@ // compile-flags: -C debug_assertions=no fn main() { - let mut it = u8::max_value()..; + let mut it = u8::MAX..; assert_eq!(it.next().unwrap(), 255); - assert_eq!(it.next().unwrap(), u8::min_value()); + assert_eq!(it.next().unwrap(), u8::MIN); - let mut it = i8::max_value()..; + let mut it = i8::MAX..; assert_eq!(it.next().unwrap(), 127); - assert_eq!(it.next().unwrap(), i8::min_value()); + assert_eq!(it.next().unwrap(), i8::MIN); } diff --git a/src/test/ui/iterators/iter-sum-overflow-debug.rs b/src/test/ui/iterators/iter-sum-overflow-debug.rs index ee4ab4d24c6ab..b7667d1bbf6d9 100644 --- a/src/test/ui/iterators/iter-sum-overflow-debug.rs +++ b/src/test/ui/iterators/iter-sum-overflow-debug.rs @@ -6,22 +6,22 @@ use std::panic; fn main() { let r = panic::catch_unwind(|| { - [1, i32::max_value()].iter().sum::(); + [1, i32::MAX].iter().sum::(); }); assert!(r.is_err()); let r = panic::catch_unwind(|| { - [2, i32::max_value()].iter().product::(); + [2, i32::MAX].iter().product::(); }); assert!(r.is_err()); let r = panic::catch_unwind(|| { - [1, i32::max_value()].iter().cloned().sum::(); + [1, i32::MAX].iter().cloned().sum::(); }); assert!(r.is_err()); let r = panic::catch_unwind(|| { - [2, i32::max_value()].iter().cloned().product::(); + [2, i32::MAX].iter().cloned().product::(); }); assert!(r.is_err()); } diff --git a/src/test/ui/iterators/iter-sum-overflow-ndebug.rs b/src/test/ui/iterators/iter-sum-overflow-ndebug.rs index 61d63d41fb87e..69f4744cc2a1a 100644 --- a/src/test/ui/iterators/iter-sum-overflow-ndebug.rs +++ b/src/test/ui/iterators/iter-sum-overflow-ndebug.rs @@ -2,13 +2,13 @@ // compile-flags: -C debug_assertions=no fn main() { - assert_eq!([1i32, i32::max_value()].iter().sum::(), - 1i32.wrapping_add(i32::max_value())); - assert_eq!([2i32, i32::max_value()].iter().product::(), - 2i32.wrapping_mul(i32::max_value())); + assert_eq!([1i32, i32::MAX].iter().sum::(), + 1i32.wrapping_add(i32::MAX)); + assert_eq!([2i32, i32::MAX].iter().product::(), + 2i32.wrapping_mul(i32::MAX)); - assert_eq!([1i32, i32::max_value()].iter().cloned().sum::(), - 1i32.wrapping_add(i32::max_value())); - assert_eq!([2i32, i32::max_value()].iter().cloned().product::(), - 2i32.wrapping_mul(i32::max_value())); + assert_eq!([1i32, i32::MAX].iter().cloned().sum::(), + 1i32.wrapping_add(i32::MAX)); + assert_eq!([2i32, i32::MAX].iter().cloned().product::(), + 2i32.wrapping_mul(i32::MAX)); } diff --git a/src/test/ui/iterators/iter-sum-overflow-overflow-checks.rs b/src/test/ui/iterators/iter-sum-overflow-overflow-checks.rs index 429f8e0bc9648..04ca7f8a31534 100644 --- a/src/test/ui/iterators/iter-sum-overflow-overflow-checks.rs +++ b/src/test/ui/iterators/iter-sum-overflow-overflow-checks.rs @@ -6,22 +6,22 @@ use std::panic; fn main() { let r = panic::catch_unwind(|| { - [1, i32::max_value()].iter().sum::(); + [1, i32::MAX].iter().sum::(); }); assert!(r.is_err()); let r = panic::catch_unwind(|| { - [2, i32::max_value()].iter().product::(); + [2, i32::MAX].iter().product::(); }); assert!(r.is_err()); let r = panic::catch_unwind(|| { - [1, i32::max_value()].iter().cloned().sum::(); + [1, i32::MAX].iter().cloned().sum::(); }); assert!(r.is_err()); let r = panic::catch_unwind(|| { - [2, i32::max_value()].iter().cloned().product::(); + [2, i32::MAX].iter().cloned().product::(); }); assert!(r.is_err()); } diff --git a/src/test/ui/iterators/skip-count-overflow.rs b/src/test/ui/iterators/skip-count-overflow.rs index d8efc948664ff..64dee3e3c8b20 100644 --- a/src/test/ui/iterators/skip-count-overflow.rs +++ b/src/test/ui/iterators/skip-count-overflow.rs @@ -3,6 +3,6 @@ // compile-flags: -C overflow-checks -C opt-level=3 fn main() { - let i = (0..usize::max_value()).chain(0..10).skip(usize::max_value()); + let i = (0..usize::MAX).chain(0..10).skip(usize::MAX); assert_eq!(i.count(), 10); } diff --git a/src/test/ui/numbers-arithmetic/i128.rs b/src/test/ui/numbers-arithmetic/i128.rs index ef558c0aa0c02..d61a1ab03b6b3 100644 --- a/src/test/ui/numbers-arithmetic/i128.rs +++ b/src/test/ui/numbers-arithmetic/i128.rs @@ -87,7 +87,7 @@ fn main() { assert_eq!((-z).checked_mul(-z), Some(0x734C_C2F2_A521)); assert_eq!((z).checked_mul(z), Some(0x734C_C2F2_A521)); assert_eq!((k).checked_mul(k), None); - let l: i128 = b(i128::min_value()); + let l: i128 = b(i128::MIN); let o: i128 = b(17); assert_eq!(l.checked_sub(b(2)), None); assert_eq!(l.checked_add(l), None); diff --git a/src/test/ui/numbers-arithmetic/int-abs-overflow.rs b/src/test/ui/numbers-arithmetic/int-abs-overflow.rs index 2bc018445db9e..10ec3f0c6624e 100644 --- a/src/test/ui/numbers-arithmetic/int-abs-overflow.rs +++ b/src/test/ui/numbers-arithmetic/int-abs-overflow.rs @@ -5,9 +5,9 @@ use std::thread; fn main() { - assert!(thread::spawn(|| i8::min_value().abs()).join().is_err()); - assert!(thread::spawn(|| i16::min_value().abs()).join().is_err()); - assert!(thread::spawn(|| i32::min_value().abs()).join().is_err()); - assert!(thread::spawn(|| i64::min_value().abs()).join().is_err()); - assert!(thread::spawn(|| isize::min_value().abs()).join().is_err()); + assert!(thread::spawn(|| i8::MIN.abs()).join().is_err()); + assert!(thread::spawn(|| i16::MIN.abs()).join().is_err()); + assert!(thread::spawn(|| i32::MIN.abs()).join().is_err()); + assert!(thread::spawn(|| i64::MIN.abs()).join().is_err()); + assert!(thread::spawn(|| isize::MIN.abs()).join().is_err()); } diff --git a/src/test/ui/numbers-arithmetic/next-power-of-two-overflow-debug.rs b/src/test/ui/numbers-arithmetic/next-power-of-two-overflow-debug.rs index e9927304f23f8..101c5d50b20b9 100644 --- a/src/test/ui/numbers-arithmetic/next-power-of-two-overflow-debug.rs +++ b/src/test/ui/numbers-arithmetic/next-power-of-two-overflow-debug.rs @@ -9,12 +9,12 @@ fn main() { macro_rules! overflow_test { ($t:ident) => ( let r = panic::catch_unwind(|| { - ($t::max_value()).next_power_of_two() + ($t::MAX).next_power_of_two() }); assert!(r.is_err()); let r = panic::catch_unwind(|| { - (($t::max_value() >> 1) + 2).next_power_of_two() + (($t::MAX >> 1) + 2).next_power_of_two() }); assert!(r.is_err()); ) diff --git a/src/test/ui/numbers-arithmetic/promoted_overflow_opt.rs b/src/test/ui/numbers-arithmetic/promoted_overflow_opt.rs index a3b8ff58a7359..4785abbc55470 100644 --- a/src/test/ui/numbers-arithmetic/promoted_overflow_opt.rs +++ b/src/test/ui/numbers-arithmetic/promoted_overflow_opt.rs @@ -5,5 +5,5 @@ fn main() { let x = &(0u32 - 1); - assert_eq!(*x, u32::max_value()) + assert_eq!(*x, u32::MAX) } diff --git a/src/test/ui/numbers-arithmetic/u128.rs b/src/test/ui/numbers-arithmetic/u128.rs index 0b2305c6e8b1a..d7e28055b2154 100644 --- a/src/test/ui/numbers-arithmetic/u128.rs +++ b/src/test/ui/numbers-arithmetic/u128.rs @@ -53,14 +53,14 @@ fn main() { assert_eq!("10000000000000000000000000000000000000000000000000000000000000000000", format!("{:b}", j)); assert_eq!("340282366920938463463374607431768211455", - format!("{}", u128::max_value())); + format!("{}", u128::MAX)); assert_eq!("147573952589676412928", format!("{:?}", j)); // common traits assert_eq!(x, b(x.clone())); // overflow checks assert_eq!((z).checked_mul(z), Some(0x734C_C2F2_A521)); assert_eq!((k).checked_mul(k), None); - let l: u128 = b(u128::max_value() - 10); + let l: u128 = b(u128::MAX - 10); let o: u128 = b(17); assert_eq!(l.checked_add(b(11)), None); assert_eq!(l.checked_sub(l), Some(0)); diff --git a/src/test/ui/simd/simd-intrinsic-generic-arithmetic-saturating.rs b/src/test/ui/simd/simd-intrinsic-generic-arithmetic-saturating.rs index e664ecadda259..b7b3ec997810e 100644 --- a/src/test/ui/simd/simd-intrinsic-generic-arithmetic-saturating.rs +++ b/src/test/ui/simd/simd-intrinsic-generic-arithmetic-saturating.rs @@ -20,7 +20,7 @@ extern "platform-intrinsic" { fn main() { // unsigned { - const M: u32 = u32::max_value(); + const M: u32 = u32::MAX; let a = u32x4(1, 2, 3, 4); let b = u32x4(2, 4, 6, 8); @@ -48,8 +48,8 @@ fn main() { // signed { - const MIN: i32 = i32::min_value(); - const MAX: i32 = i32::max_value(); + const MIN: i32 = i32::MIN; + const MAX: i32 = i32::MAX; let a = i32x4(1, 2, 3, 4); let b = i32x4(2, 4, 6, 8); diff --git a/src/test/ui/simd/simd-intrinsic-generic-bitmask.rs b/src/test/ui/simd/simd-intrinsic-generic-bitmask.rs index b28f742a92e94..a323bd9e82b4a 100644 --- a/src/test/ui/simd/simd-intrinsic-generic-bitmask.rs +++ b/src/test/ui/simd/simd-intrinsic-generic-bitmask.rs @@ -39,7 +39,7 @@ fn main() { let e = 0b_1101; // Check usize / isize - let msize: Tx4 = Tx4(usize::max_value(), 0, usize::max_value(), usize::max_value()); + let msize: Tx4 = Tx4(usize::MAX, 0, usize::MAX, usize::MAX); unsafe { let r: u8 = simd_bitmask(z); diff --git a/src/test/ui/simd/simd-intrinsic-generic-reduction.rs b/src/test/ui/simd/simd-intrinsic-generic-reduction.rs index 4195444a73f67..8b5afeac0bc2d 100644 --- a/src/test/ui/simd/simd-intrinsic-generic-reduction.rs +++ b/src/test/ui/simd/simd-intrinsic-generic-reduction.rs @@ -100,7 +100,7 @@ fn main() { let r: u32 = simd_reduce_max(x); assert_eq!(r, 4_u32); - let t = u32::max_value(); + let t = u32::MAX; let x = u32x4(t, t, t, t); let r: u32 = simd_reduce_and(x); assert_eq!(r, t); diff --git a/src/tools/clippy/clippy_lints/src/consts.rs b/src/tools/clippy/clippy_lints/src/consts.rs index 81ddc8c0067c7..22c5acca064e9 100644 --- a/src/tools/clippy/clippy_lints/src/consts.rs +++ b/src/tools/clippy/clippy_lints/src/consts.rs @@ -254,11 +254,11 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { if let ["core", "num", int_impl, "max_value"] = *def_path; then { let value = match int_impl { - "" => i8::max_value() as u128, - "" => i16::max_value() as u128, - "" => i32::max_value() as u128, - "" => i64::max_value() as u128, - "" => i128::max_value() as u128, + "" => i8::MAX as u128, + "" => i16::MAX as u128, + "" => i32::MAX as u128, + "" => i64::MAX as u128, + "" => i128::MAX as u128, _ => return None, }; Some(Constant::Int(value)) diff --git a/src/tools/clippy/clippy_lints/src/enum_clike.rs b/src/tools/clippy/clippy_lints/src/enum_clike.rs index a1fed3fb6e205..12b62f5cf9789 100644 --- a/src/tools/clippy/clippy_lints/src/enum_clike.rs +++ b/src/tools/clippy/clippy_lints/src/enum_clike.rs @@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant { continue; } }, - ty::Uint(UintTy::Usize) if val > u128::from(u32::max_value()) => {}, + ty::Uint(UintTy::Usize) if val > u128::from(u32::MAX) => {}, _ => continue, } span_lint( diff --git a/src/tools/clippy/clippy_lints/src/types.rs b/src/tools/clippy/clippy_lints/src/types.rs index 6ed9ff22e4664..4336d8205a56c 100644 --- a/src/tools/clippy/clippy_lints/src/types.rs +++ b/src/tools/clippy/clippy_lints/src/types.rs @@ -1852,18 +1852,18 @@ fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_ let which = match (&ty.kind, cv) { (&ty::Bool, Constant::Bool(false)) | (&ty::Uint(_), Constant::Int(0)) => Minimum, (&ty::Int(ity), Constant::Int(i)) - if i == unsext(cx.tcx, i128::min_value() >> (128 - int_bits(cx.tcx, ity)), ity) => + if i == unsext(cx.tcx, i128::MIN >> (128 - int_bits(cx.tcx, ity)), ity) => { Minimum }, (&ty::Bool, Constant::Bool(true)) => Maximum, (&ty::Int(ity), Constant::Int(i)) - if i == unsext(cx.tcx, i128::max_value() >> (128 - int_bits(cx.tcx, ity)), ity) => + if i == unsext(cx.tcx, i128::MAX >> (128 - int_bits(cx.tcx, ity)), ity) => { Maximum }, - (&ty::Uint(uty), Constant::Int(i)) if clip(cx.tcx, u128::max_value(), uty) == i => Maximum, + (&ty::Uint(uty), Constant::Int(i)) if clip(cx.tcx, u128::MAX, uty) == i => Maximum, _ => return None, }; @@ -1945,7 +1945,7 @@ impl FullInt { fn cmp_s_u(s: i128, u: u128) -> Ordering { if s < 0 { Ordering::Less - } else if u > (i128::max_value() as u128) { + } else if u > (i128::MAX as u128) { Ordering::Greater } else { (s as u128).cmp(&u) @@ -1990,48 +1990,48 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>) match pre_cast_ty.kind { ty::Int(int_ty) => Some(match int_ty { IntTy::I8 => ( - FullInt::S(i128::from(i8::min_value())), - FullInt::S(i128::from(i8::max_value())), + FullInt::S(i128::from(i8::MIN)), + FullInt::S(i128::from(i8::MAX)), ), IntTy::I16 => ( - FullInt::S(i128::from(i16::min_value())), - FullInt::S(i128::from(i16::max_value())), + FullInt::S(i128::from(i16::MIN)), + FullInt::S(i128::from(i16::MAX)), ), IntTy::I32 => ( - FullInt::S(i128::from(i32::min_value())), - FullInt::S(i128::from(i32::max_value())), + FullInt::S(i128::from(i32::MIN)), + FullInt::S(i128::from(i32::MAX)), ), IntTy::I64 => ( - FullInt::S(i128::from(i64::min_value())), - FullInt::S(i128::from(i64::max_value())), + FullInt::S(i128::from(i64::MIN)), + FullInt::S(i128::from(i64::MAX)), ), - IntTy::I128 => (FullInt::S(i128::min_value()), FullInt::S(i128::max_value())), + IntTy::I128 => (FullInt::S(i128::MIN), FullInt::S(i128::MAX)), IntTy::Isize => ( - FullInt::S(isize::min_value() as i128), - FullInt::S(isize::max_value() as i128), + FullInt::S(isize::MIN as i128), + FullInt::S(isize::MAX as i128), ), }), ty::Uint(uint_ty) => Some(match uint_ty { UintTy::U8 => ( - FullInt::U(u128::from(u8::min_value())), - FullInt::U(u128::from(u8::max_value())), + FullInt::U(u128::from(u8::MIN)), + FullInt::U(u128::from(u8::MAX)), ), UintTy::U16 => ( - FullInt::U(u128::from(u16::min_value())), - FullInt::U(u128::from(u16::max_value())), + FullInt::U(u128::from(u16::MIN)), + FullInt::U(u128::from(u16::MAX)), ), UintTy::U32 => ( - FullInt::U(u128::from(u32::min_value())), - FullInt::U(u128::from(u32::max_value())), + FullInt::U(u128::from(u32::MIN)), + FullInt::U(u128::from(u32::MAX)), ), UintTy::U64 => ( - FullInt::U(u128::from(u64::min_value())), - FullInt::U(u128::from(u64::max_value())), + FullInt::U(u128::from(u64::MIN)), + FullInt::U(u128::from(u64::MAX)), ), - UintTy::U128 => (FullInt::U(u128::min_value()), FullInt::U(u128::max_value())), + UintTy::U128 => (FullInt::U(u128::MIN), FullInt::U(u128::MAX)), UintTy::Usize => ( - FullInt::U(usize::min_value() as u128), - FullInt::U(usize::max_value() as u128), + FullInt::U(usize::MIN as u128), + FullInt::U(usize::MAX as u128), ), }), _ => None, diff --git a/src/tools/clippy/tests/ui/cast.rs b/src/tools/clippy/tests/ui/cast.rs index 7e0b211d862ca..8ee0969b0f076 100644 --- a/src/tools/clippy/tests/ui/cast.rs +++ b/src/tools/clippy/tests/ui/cast.rs @@ -37,11 +37,11 @@ fn main() { 1isize as usize; -1isize as usize; 0i8 as u8; - i8::max_value() as u8; - i16::max_value() as u16; - i32::max_value() as u32; - i64::max_value() as u64; - i128::max_value() as u128; + i8::MAX as u8; + i16::MAX as u16; + i32::MAX as u32; + i64::MAX as u64; + i128::MAX as u128; (-1i8).abs() as u8; (-1i16).abs() as u16; diff --git a/src/tools/clippy/tests/ui/checked_conversions.fixed b/src/tools/clippy/tests/ui/checked_conversions.fixed index 7febd6f376135..5315614d72563 100644 --- a/src/tools/clippy/tests/ui/checked_conversions.fixed +++ b/src/tools/clippy/tests/ui/checked_conversions.fixed @@ -3,14 +3,14 @@ #![warn(clippy::checked_conversions)] #![allow(clippy::cast_lossless)] #![allow(dead_code)] -use std::convert::TryFrom; +//use std::convert::TryFrom; // Positive tests // Signed to unsigned fn i64_to_u32(value: i64) -> Option { - if u32::try_from(value).is_ok() { + if value <= (u32::MAX as i64) && value >= 0 { Some(value as u32) } else { None @@ -18,7 +18,7 @@ fn i64_to_u32(value: i64) -> Option { } fn i64_to_u16(value: i64) -> Option { - if u16::try_from(value).is_ok() { + if value <= i64::from(u16::MAX) && value >= 0 { Some(value as u16) } else { None @@ -26,7 +26,7 @@ fn i64_to_u16(value: i64) -> Option { } fn isize_to_u8(value: isize) -> Option { - if u8::try_from(value).is_ok() { + if value <= (u8::MAX as isize) && value >= 0 { Some(value as u8) } else { None @@ -36,7 +36,7 @@ fn isize_to_u8(value: isize) -> Option { // Signed to signed fn i64_to_i32(value: i64) -> Option { - if i32::try_from(value).is_ok() { + if value <= (i32::MAX as i64) && value >= (i32::MIN as i64) { Some(value as i32) } else { None @@ -44,7 +44,7 @@ fn i64_to_i32(value: i64) -> Option { } fn i64_to_i16(value: i64) -> Option { - if i16::try_from(value).is_ok() { + if value <= i64::from(i16::MAX) && value >= i64::from(i16::MIN) { Some(value as i16) } else { None @@ -54,7 +54,7 @@ fn i64_to_i16(value: i64) -> Option { // Unsigned to X fn u32_to_i32(value: u32) -> Option { - if i32::try_from(value).is_ok() { + if value <= i32::MAX as u32 { Some(value as i32) } else { None @@ -62,7 +62,7 @@ fn u32_to_i32(value: u32) -> Option { } fn usize_to_isize(value: usize) -> isize { - if isize::try_from(value).is_ok() && value as i32 == 5 { + if value <= isize::MAX as usize && value as i32 == 5 { 5 } else { 1 @@ -70,7 +70,7 @@ fn usize_to_isize(value: usize) -> isize { } fn u32_to_u16(value: u32) -> isize { - if u16::try_from(value).is_ok() && value as i32 == 5 { + if value <= u16::MAX as u32 && value as i32 == 5 { 5 } else { 1 @@ -80,7 +80,7 @@ fn u32_to_u16(value: u32) -> isize { // Negative tests fn no_i64_to_i32(value: i64) -> Option { - if value <= (i32::max_value() as i64) && value >= 0 { + if value <= (i32::MAX as i64) && value >= 0 { Some(value as i32) } else { None @@ -88,7 +88,7 @@ fn no_i64_to_i32(value: i64) -> Option { } fn no_isize_to_u8(value: isize) -> Option { - if value <= (u8::max_value() as isize) && value >= (u8::min_value() as isize) { + if value <= (u8::MAX as isize) && value >= (u8::MIN as isize) { Some(value as u8) } else { None diff --git a/src/tools/clippy/tests/ui/checked_conversions.rs b/src/tools/clippy/tests/ui/checked_conversions.rs index a643354e2438f..5315614d72563 100644 --- a/src/tools/clippy/tests/ui/checked_conversions.rs +++ b/src/tools/clippy/tests/ui/checked_conversions.rs @@ -3,14 +3,14 @@ #![warn(clippy::checked_conversions)] #![allow(clippy::cast_lossless)] #![allow(dead_code)] -use std::convert::TryFrom; +//use std::convert::TryFrom; // Positive tests // Signed to unsigned fn i64_to_u32(value: i64) -> Option { - if value <= (u32::max_value() as i64) && value >= 0 { + if value <= (u32::MAX as i64) && value >= 0 { Some(value as u32) } else { None @@ -18,7 +18,7 @@ fn i64_to_u32(value: i64) -> Option { } fn i64_to_u16(value: i64) -> Option { - if value <= i64::from(u16::max_value()) && value >= 0 { + if value <= i64::from(u16::MAX) && value >= 0 { Some(value as u16) } else { None @@ -26,7 +26,7 @@ fn i64_to_u16(value: i64) -> Option { } fn isize_to_u8(value: isize) -> Option { - if value <= (u8::max_value() as isize) && value >= 0 { + if value <= (u8::MAX as isize) && value >= 0 { Some(value as u8) } else { None @@ -36,7 +36,7 @@ fn isize_to_u8(value: isize) -> Option { // Signed to signed fn i64_to_i32(value: i64) -> Option { - if value <= (i32::max_value() as i64) && value >= (i32::min_value() as i64) { + if value <= (i32::MAX as i64) && value >= (i32::MIN as i64) { Some(value as i32) } else { None @@ -44,7 +44,7 @@ fn i64_to_i32(value: i64) -> Option { } fn i64_to_i16(value: i64) -> Option { - if value <= i64::from(i16::max_value()) && value >= i64::from(i16::min_value()) { + if value <= i64::from(i16::MAX) && value >= i64::from(i16::MIN) { Some(value as i16) } else { None @@ -54,7 +54,7 @@ fn i64_to_i16(value: i64) -> Option { // Unsigned to X fn u32_to_i32(value: u32) -> Option { - if value <= i32::max_value() as u32 { + if value <= i32::MAX as u32 { Some(value as i32) } else { None @@ -62,7 +62,7 @@ fn u32_to_i32(value: u32) -> Option { } fn usize_to_isize(value: usize) -> isize { - if value <= isize::max_value() as usize && value as i32 == 5 { + if value <= isize::MAX as usize && value as i32 == 5 { 5 } else { 1 @@ -70,7 +70,7 @@ fn usize_to_isize(value: usize) -> isize { } fn u32_to_u16(value: u32) -> isize { - if value <= u16::max_value() as u32 && value as i32 == 5 { + if value <= u16::MAX as u32 && value as i32 == 5 { 5 } else { 1 @@ -80,7 +80,7 @@ fn u32_to_u16(value: u32) -> isize { // Negative tests fn no_i64_to_i32(value: i64) -> Option { - if value <= (i32::max_value() as i64) && value >= 0 { + if value <= (i32::MAX as i64) && value >= 0 { Some(value as i32) } else { None @@ -88,7 +88,7 @@ fn no_i64_to_i32(value: i64) -> Option { } fn no_isize_to_u8(value: isize) -> Option { - if value <= (u8::max_value() as isize) && value >= (u8::min_value() as isize) { + if value <= (u8::MAX as isize) && value >= (u8::MIN as isize) { Some(value as u8) } else { None diff --git a/src/tools/clippy/tests/ui/checked_conversions.stderr b/src/tools/clippy/tests/ui/checked_conversions.stderr index f678f009621f8..e69de29bb2d1d 100644 --- a/src/tools/clippy/tests/ui/checked_conversions.stderr +++ b/src/tools/clippy/tests/ui/checked_conversions.stderr @@ -1,52 +0,0 @@ -error: Checked cast can be simplified. - --> $DIR/checked_conversions.rs:13:8 - | -LL | if value <= (u32::max_value() as i64) && value >= 0 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()` - | - = note: `-D clippy::checked-conversions` implied by `-D warnings` - -error: Checked cast can be simplified. - --> $DIR/checked_conversions.rs:21:8 - | -LL | if value <= i64::from(u16::max_value()) && value >= 0 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()` - -error: Checked cast can be simplified. - --> $DIR/checked_conversions.rs:29:8 - | -LL | if value <= (u8::max_value() as isize) && value >= 0 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u8::try_from(value).is_ok()` - -error: Checked cast can be simplified. - --> $DIR/checked_conversions.rs:39:8 - | -LL | if value <= (i32::max_value() as i64) && value >= (i32::min_value() as i64) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()` - -error: Checked cast can be simplified. - --> $DIR/checked_conversions.rs:47:8 - | -LL | if value <= i64::from(i16::max_value()) && value >= i64::from(i16::min_value()) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i16::try_from(value).is_ok()` - -error: Checked cast can be simplified. - --> $DIR/checked_conversions.rs:57:8 - | -LL | if value <= i32::max_value() as u32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()` - -error: Checked cast can be simplified. - --> $DIR/checked_conversions.rs:65:8 - | -LL | if value <= isize::max_value() as usize && value as i32 == 5 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `isize::try_from(value).is_ok()` - -error: Checked cast can be simplified. - --> $DIR/checked_conversions.rs:73:8 - | -LL | if value <= u16::max_value() as u32 && value as i32 == 5 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()` - -error: aborting due to 8 previous errors - diff --git a/src/tools/clippy/tests/ui/implicit_saturating_sub.rs b/src/tools/clippy/tests/ui/implicit_saturating_sub.rs index 24cb216e79bf3..2f32a7b157821 100644 --- a/src/tools/clippy/tests/ui/implicit_saturating_sub.rs +++ b/src/tools/clippy/tests/ui/implicit_saturating_sub.rs @@ -110,7 +110,7 @@ fn main() { } // Lint - if i_8 > i8::min_value() { + if i_8 > i8::MIN { i_8 -= 1; } @@ -120,7 +120,7 @@ fn main() { } // Lint - if i_8 != i8::min_value() { + if i_8 != i8::MIN { i_8 -= 1; } @@ -135,7 +135,7 @@ fn main() { } // Lint - if i_16 > i16::min_value() { + if i_16 > i16::MIN { i_16 -= 1; } @@ -145,7 +145,7 @@ fn main() { } // Lint - if i_16 != i16::min_value() { + if i_16 != i16::MIN { i_16 -= 1; } @@ -160,7 +160,7 @@ fn main() { } // Lint - if i_32 > i32::min_value() { + if i_32 > i32::MIN { i_32 -= 1; } @@ -170,7 +170,7 @@ fn main() { } // Lint - if i_32 != i32::min_value() { + if i_32 != i32::MIN { i_32 -= 1; } @@ -180,7 +180,7 @@ fn main() { let mut i_64: i64 = endi_64 - starti_64; // Lint - if i64::min_value() < i_64 { + if i64::MIN < i_64 { i_64 -= 1; } diff --git a/src/tools/clippy/tests/ui/implicit_saturating_sub.stderr b/src/tools/clippy/tests/ui/implicit_saturating_sub.stderr index a8ba870b1dda6..2eb2023b3b9ef 100644 --- a/src/tools/clippy/tests/ui/implicit_saturating_sub.stderr +++ b/src/tools/clippy/tests/ui/implicit_saturating_sub.stderr @@ -75,7 +75,7 @@ LL | | } error: Implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:113:5 | -LL | / if i_8 > i8::min_value() { +LL | / if i_8 > i8::MIN { LL | | i_8 -= 1; LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` @@ -91,7 +91,7 @@ LL | | } error: Implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:123:5 | -LL | / if i_8 != i8::min_value() { +LL | / if i_8 != i8::MIN { LL | | i_8 -= 1; LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` @@ -107,7 +107,7 @@ LL | | } error: Implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:138:5 | -LL | / if i_16 > i16::min_value() { +LL | / if i_16 > i16::MIN { LL | | i_16 -= 1; LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` @@ -123,7 +123,7 @@ LL | | } error: Implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:148:5 | -LL | / if i_16 != i16::min_value() { +LL | / if i_16 != i16::MIN { LL | | i_16 -= 1; LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` @@ -139,7 +139,7 @@ LL | | } error: Implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:163:5 | -LL | / if i_32 > i32::min_value() { +LL | / if i_32 > i32::MIN { LL | | i_32 -= 1; LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` @@ -155,7 +155,7 @@ LL | | } error: Implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:173:5 | -LL | / if i_32 != i32::min_value() { +LL | / if i_32 != i32::MIN { LL | | i_32 -= 1; LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` @@ -163,7 +163,7 @@ LL | | } error: Implicitly performing saturating subtraction --> $DIR/implicit_saturating_sub.rs:183:5 | -LL | / if i64::min_value() < i_64 { +LL | / if i64::MIN < i_64 { LL | | i_64 -= 1; LL | | } | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` diff --git a/src/tools/unicode-table-generator/src/raw_emitter.rs b/src/tools/unicode-table-generator/src/raw_emitter.rs index 95b63aca1549b..63cc29b670f6b 100644 --- a/src/tools/unicode-table-generator/src/raw_emitter.rs +++ b/src/tools/unicode-table-generator/src/raw_emitter.rs @@ -43,7 +43,7 @@ impl RawEmitter { words.push(0); let unique_words = words.iter().cloned().collect::>().into_iter().collect::>(); - if unique_words.len() > u8::max_value() as usize { + if unique_words.len() > u8::MAX as usize { panic!("cannot pack {} into 8 bits", unique_words.len()); } // needed for the chunk mapping to work