X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibcore%2Fnum%2Fmod.rs;h=889ce2f211e14229f079e477e97207cb1ba9e24f;hb=977d69fc1992b0cef8d8ff020261d5bf9ede7424;hp=43c5f7cf6b939c4a418400c464f5292425ffdf8d;hpb=d6414f5f8c30593cd250fddf315e6f0098c3239a;p=rust.git diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 43c5f7cf6b9..889ce2f211e 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -266,11 +266,10 @@ macro_rules! int_impl { Basic usage: ``` -#![feature(assoc_int_consts)] ", $Feature, "assert_eq!(", stringify!($SelfT), "::MIN, ", stringify!($Min), ");", $EndFeature, " ```"), - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN: Self = !0 ^ ((!0 as $UnsignedT) >> 1) as Self; } @@ -282,36 +281,13 @@ macro_rules! int_impl { Basic usage: ``` -#![feature(assoc_int_consts)] ", $Feature, "assert_eq!(", stringify!($SelfT), "::MAX, ", stringify!($Max), ");", $EndFeature, " ```"), - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MAX: Self = !Self::MIN; } - doc_comment! { - "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! { - "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 - } - } - doc_comment! { concat!("Converts a string slice in a given base to an integer. @@ -369,7 +345,7 @@ pub const fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() } Basic usage: ``` -", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 1);", $EndFeature, " +", $Feature, "assert_eq!(", stringify!($SelfT), "::MAX.count_zeros(), 1);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] @@ -706,8 +682,8 @@ pub const fn to_le(self) -> Self { ``` ", $Feature, "assert_eq!((", stringify!($SelfT), -"::max_value() - 2).checked_add(1), Some(", stringify!($SelfT), "::max_value() - 1)); -assert_eq!((", stringify!($SelfT), "::max_value() - 2).checked_add(3), None);", +"::MAX - 2).checked_add(1), Some(", stringify!($SelfT), "::MAX - 1)); +assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] @@ -731,8 +707,8 @@ pub const fn checked_add(self, rhs: Self) -> Option { ``` ", $Feature, "assert_eq!((", stringify!($SelfT), -"::min_value() + 2).checked_sub(1), Some(", stringify!($SelfT), "::min_value() + 1)); -assert_eq!((", stringify!($SelfT), "::min_value() + 2).checked_sub(3), None);", +"::MIN + 2).checked_sub(1), Some(", stringify!($SelfT), "::MIN + 1)); +assert_eq!((", stringify!($SelfT), "::MIN + 2).checked_sub(3), None);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] @@ -756,8 +732,8 @@ pub const fn checked_sub(self, rhs: Self) -> Option { ``` ", $Feature, "assert_eq!(", stringify!($SelfT), -"::max_value().checked_mul(1), Some(", stringify!($SelfT), "::max_value())); -assert_eq!(", stringify!($SelfT), "::max_value().checked_mul(2), None);", +"::MAX.checked_mul(1), Some(", stringify!($SelfT), "::MAX)); +assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(2), None);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] @@ -781,8 +757,8 @@ pub const fn checked_mul(self, rhs: Self) -> Option { ``` ", $Feature, "assert_eq!((", stringify!($SelfT), -"::min_value() + 1).checked_div(-1), Some(", stringify!($Max), ")); -assert_eq!(", stringify!($SelfT), "::min_value().checked_div(-1), None); +"::MIN + 1).checked_div(-1), Some(", stringify!($Max), ")); +assert_eq!(", stringify!($SelfT), "::MIN.checked_div(-1), None); assert_eq!((1", stringify!($SelfT), ").checked_div(0), None);", $EndFeature, " ```"), @@ -811,8 +787,8 @@ pub const fn checked_div(self, rhs: Self) -> Option { ``` assert_eq!((", stringify!($SelfT), -"::min_value() + 1).checked_div_euclid(-1), Some(", stringify!($Max), ")); -assert_eq!(", stringify!($SelfT), "::min_value().checked_div_euclid(-1), None); +"::MIN + 1).checked_div_euclid(-1), Some(", stringify!($Max), ")); +assert_eq!(", stringify!($SelfT), "::MIN.checked_div_euclid(-1), None); assert_eq!((1", stringify!($SelfT), ").checked_div_euclid(0), None); ```"), #[stable(feature = "euclidean_division", since = "1.38.0")] @@ -838,8 +814,7 @@ pub const fn checked_div_euclid(self, rhs: Self) -> Option { Basic usage: ``` -", $Feature, "use std::", stringify!($SelfT), "; - +", $Feature, " assert_eq!(5", stringify!($SelfT), ".checked_rem(2), Some(1)); assert_eq!(5", stringify!($SelfT), ".checked_rem(0), None); assert_eq!(", stringify!($SelfT), "::MIN.checked_rem(-1), None);", @@ -869,8 +844,6 @@ pub const fn checked_rem(self, rhs: Self) -> Option { Basic usage: ``` -use std::", stringify!($SelfT), "; - assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(2), Some(1)); assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(0), None); assert_eq!(", stringify!($SelfT), "::MIN.checked_rem_euclid(-1), None); @@ -897,8 +870,7 @@ pub const fn checked_rem_euclid(self, rhs: Self) -> Option { Basic usage: ``` -", $Feature, "use std::", stringify!($SelfT), "; - +", $Feature, " assert_eq!(5", stringify!($SelfT), ".checked_neg(), Some(-5)); assert_eq!(", stringify!($SelfT), "::MIN.checked_neg(), None);", $EndFeature, " @@ -969,8 +941,7 @@ pub const fn checked_shr(self, rhs: u32) -> Option { Basic usage: ``` -", $Feature, "use std::", stringify!($SelfT), "; - +", $Feature, " assert_eq!((-5", stringify!($SelfT), ").checked_abs(), Some(5)); assert_eq!(", stringify!($SelfT), "::MIN.checked_abs(), None);", $EndFeature, " @@ -997,7 +968,7 @@ pub const fn checked_abs(self) -> Option { ``` ", $Feature, "assert_eq!(8", stringify!($SelfT), ".checked_pow(2), Some(64)); -assert_eq!(", stringify!($SelfT), "::max_value().checked_pow(2), None);", +assert_eq!(", stringify!($SelfT), "::MAX.checked_pow(2), None);", $EndFeature, " ```"), @@ -1039,10 +1010,10 @@ pub const fn checked_pow(self, mut exp: u32) -> Option { ``` ", $Feature, "assert_eq!(100", stringify!($SelfT), ".saturating_add(1), 101); -assert_eq!(", stringify!($SelfT), "::max_value().saturating_add(100), ", stringify!($SelfT), -"::max_value()); -assert_eq!(", stringify!($SelfT), "::min_value().saturating_add(-1), ", stringify!($SelfT), -"::min_value());", +assert_eq!(", stringify!($SelfT), "::MAX.saturating_add(100), ", stringify!($SelfT), +"::MAX); +assert_eq!(", stringify!($SelfT), "::MIN.saturating_add(-1), ", stringify!($SelfT), +"::MIN);", $EndFeature, " ```"), @@ -1066,10 +1037,10 @@ pub const fn saturating_add(self, rhs: Self) -> Self { ``` ", $Feature, "assert_eq!(100", stringify!($SelfT), ".saturating_sub(127), -27); -assert_eq!(", stringify!($SelfT), "::min_value().saturating_sub(100), ", stringify!($SelfT), -"::min_value()); -assert_eq!(", stringify!($SelfT), "::max_value().saturating_sub(-1), ", stringify!($SelfT), -"::max_value());", +assert_eq!(", stringify!($SelfT), "::MIN.saturating_sub(100), ", stringify!($SelfT), +"::MIN); +assert_eq!(", stringify!($SelfT), "::MAX.saturating_sub(-1), ", stringify!($SelfT), +"::MAX);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] @@ -1094,10 +1065,10 @@ pub const fn saturating_sub(self, rhs: Self) -> Self { ", $Feature, "#![feature(saturating_neg)] assert_eq!(100", stringify!($SelfT), ".saturating_neg(), -100); assert_eq!((-100", stringify!($SelfT), ").saturating_neg(), 100); -assert_eq!(", stringify!($SelfT), "::min_value().saturating_neg(), ", stringify!($SelfT), -"::max_value()); -assert_eq!(", stringify!($SelfT), "::max_value().saturating_neg(), ", stringify!($SelfT), -"::min_value() + 1);", +assert_eq!(", stringify!($SelfT), "::MIN.saturating_neg(), ", stringify!($SelfT), +"::MAX); +assert_eq!(", stringify!($SelfT), "::MAX.saturating_neg(), ", stringify!($SelfT), +"::MIN + 1);", $EndFeature, " ```"), @@ -1121,10 +1092,10 @@ pub const fn saturating_neg(self) -> Self { ", $Feature, "#![feature(saturating_neg)] assert_eq!(100", stringify!($SelfT), ".saturating_abs(), 100); assert_eq!((-100", stringify!($SelfT), ").saturating_abs(), 100); -assert_eq!(", stringify!($SelfT), "::min_value().saturating_abs(), ", stringify!($SelfT), -"::max_value()); -assert_eq!((", stringify!($SelfT), "::min_value() + 1).saturating_abs(), ", stringify!($SelfT), -"::max_value());", +assert_eq!(", stringify!($SelfT), "::MIN.saturating_abs(), ", stringify!($SelfT), +"::MAX); +assert_eq!((", stringify!($SelfT), "::MIN + 1).saturating_abs(), ", stringify!($SelfT), +"::MAX);", $EndFeature, " ```"), @@ -1149,8 +1120,7 @@ pub const fn saturating_abs(self) -> Self { Basic usage: ``` -", $Feature, "use std::", stringify!($SelfT), "; - +", $Feature, " assert_eq!(10", stringify!($SelfT), ".saturating_mul(12), 120); assert_eq!(", stringify!($SelfT), "::MAX.saturating_mul(10), ", stringify!($SelfT), "::MAX); assert_eq!(", stringify!($SelfT), "::MIN.saturating_mul(10), ", stringify!($SelfT), "::MIN);", @@ -1182,8 +1152,7 @@ pub const fn saturating_mul(self, rhs: Self) -> Self { Basic usage: ``` -", $Feature, "use std::", stringify!($SelfT), "; - +", $Feature, " assert_eq!((-4", stringify!($SelfT), ").saturating_pow(3), -64); assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(2), ", stringify!($SelfT), "::MAX); assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(3), ", stringify!($SelfT), "::MIN);", @@ -1213,8 +1182,8 @@ pub const fn saturating_pow(self, exp: u32) -> Self { ``` ", $Feature, "assert_eq!(100", stringify!($SelfT), ".wrapping_add(27), 127); -assert_eq!(", stringify!($SelfT), "::max_value().wrapping_add(2), ", stringify!($SelfT), -"::min_value() + 1);", +assert_eq!(", stringify!($SelfT), "::MAX.wrapping_add(2), ", stringify!($SelfT), +"::MIN + 1);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] @@ -1237,8 +1206,8 @@ pub const fn wrapping_add(self, rhs: Self) -> Self { ``` ", $Feature, "assert_eq!(0", stringify!($SelfT), ".wrapping_sub(127), -127); -assert_eq!((-2", stringify!($SelfT), ").wrapping_sub(", stringify!($SelfT), "::max_value()), ", -stringify!($SelfT), "::max_value());", +assert_eq!((-2", stringify!($SelfT), ").wrapping_sub(", stringify!($SelfT), "::MAX), ", +stringify!($SelfT), "::MAX);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] @@ -1409,8 +1378,8 @@ pub const fn wrapping_rem_euclid(self, rhs: Self) -> Self { ``` ", $Feature, "assert_eq!(100", stringify!($SelfT), ".wrapping_neg(), -100); -assert_eq!(", stringify!($SelfT), "::min_value().wrapping_neg(), ", stringify!($SelfT), -"::min_value());", +assert_eq!(", stringify!($SelfT), "::MIN.wrapping_neg(), ", stringify!($SelfT), +"::MIN);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] @@ -1500,8 +1469,8 @@ pub const fn wrapping_shr(self, rhs: u32) -> Self { ``` ", $Feature, "assert_eq!(100", stringify!($SelfT), ".wrapping_abs(), 100); assert_eq!((-100", stringify!($SelfT), ").wrapping_abs(), 100); -assert_eq!(", stringify!($SelfT), "::min_value().wrapping_abs(), ", stringify!($SelfT), -"::min_value()); +assert_eq!(", stringify!($SelfT), "::MIN.wrapping_abs(), ", stringify!($SelfT), +"::MIN); assert_eq!((-128i8).wrapping_abs() as u8, 128);", $EndFeature, " ```"), @@ -1572,8 +1541,7 @@ pub const fn wrapping_pow(self, mut exp: u32) -> Self { Basic usage: ``` -", $Feature, "use std::", stringify!($SelfT), "; - +", $Feature, " assert_eq!(5", stringify!($SelfT), ".overflowing_add(2), (7, false)); assert_eq!(", stringify!($SelfT), "::MAX.overflowing_add(1), (", stringify!($SelfT), "::MIN, true));", $EndFeature, " @@ -1600,8 +1568,7 @@ pub const fn overflowing_add(self, rhs: Self) -> (Self, bool) { Basic usage: ``` -", $Feature, "use std::", stringify!($SelfT), "; - +", $Feature, " assert_eq!(5", stringify!($SelfT), ".overflowing_sub(2), (3, false)); assert_eq!(", stringify!($SelfT), "::MIN.overflowing_sub(1), (", stringify!($SelfT), "::MAX, true));", $EndFeature, " @@ -1658,8 +1625,7 @@ pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool) { Basic usage: ``` -", $Feature, "use std::", stringify!($SelfT), "; - +", $Feature, " assert_eq!(5", stringify!($SelfT), ".overflowing_div(2), (2, false)); assert_eq!(", stringify!($SelfT), "::MIN.overflowing_div(-1), (", stringify!($SelfT), "::MIN, true));", @@ -1694,8 +1660,6 @@ pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) { Basic usage: ``` -use std::", stringify!($SelfT), "; - assert_eq!(5", stringify!($SelfT), ".overflowing_div_euclid(2), (2, false)); assert_eq!(", stringify!($SelfT), "::MIN.overflowing_div_euclid(-1), (", stringify!($SelfT), "::MIN, true)); @@ -1729,8 +1693,7 @@ pub const fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) { Basic usage: ``` -", $Feature, "use std::", stringify!($SelfT), "; - +", $Feature, " assert_eq!(5", stringify!($SelfT), ".overflowing_rem(2), (1, false)); assert_eq!(", stringify!($SelfT), "::MIN.overflowing_rem(-1), (0, true));", $EndFeature, " @@ -1765,8 +1728,6 @@ pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) { Basic usage: ``` -use std::", stringify!($SelfT), "; - assert_eq!(5", stringify!($SelfT), ".overflowing_rem_euclid(2), (1, false)); assert_eq!(", stringify!($SelfT), "::MIN.overflowing_rem_euclid(-1), (0, true)); ```"), @@ -1797,8 +1758,6 @@ pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) { Basic usage: ``` -", $Feature, "use std::", stringify!($SelfT), "; - assert_eq!(2", stringify!($SelfT), ".overflowing_neg(), (-2, false)); assert_eq!(", stringify!($SelfT), "::MIN.overflowing_neg(), (", stringify!($SelfT), "::MIN, true));", $EndFeature, " @@ -1884,8 +1843,8 @@ pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool) { ``` ", $Feature, "assert_eq!(10", stringify!($SelfT), ".overflowing_abs(), (10, false)); assert_eq!((-10", stringify!($SelfT), ").overflowing_abs(), (10, false)); -assert_eq!((", stringify!($SelfT), "::min_value()).overflowing_abs(), (", stringify!($SelfT), -"::min_value(), true));", +assert_eq!((", stringify!($SelfT), "::MIN).overflowing_abs(), (", stringify!($SelfT), +"::MIN, true));", $EndFeature, " ```"), #[stable(feature = "no_panic_abs", since = "1.13.0")] @@ -2083,10 +2042,10 @@ pub const fn rem_euclid(self, rhs: Self) -> Self { # Overflow behavior -The absolute value of `", stringify!($SelfT), "::min_value()` cannot be represented as an +The absolute value of `", stringify!($SelfT), "::MIN` cannot be represented as an `", stringify!($SelfT), "`, and attempting to calculate it will cause an overflow. This means that code in debug mode will trigger a panic on this case and optimized code will return `", -stringify!($SelfT), "::min_value()` without a panic. +stringify!($SelfT), "::MIN` without a panic. # Examples @@ -2367,6 +2326,38 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), unsafe { mem::transmute(bytes) } } } + + 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 + } + } } } @@ -2449,10 +2440,9 @@ macro_rules! uint_impl { Basic usage: ``` -#![feature(assoc_int_consts)] ", $Feature, "assert_eq!(", stringify!($SelfT), "::MIN, 0);", $EndFeature, " ```"), - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN: Self = 0; } @@ -2464,32 +2454,13 @@ macro_rules! uint_impl { Basic usage: ``` -#![feature(assoc_int_consts)] ", $Feature, "assert_eq!(", stringify!($SelfT), "::MAX, ", stringify!($MaxV), ");", $EndFeature, " ```"), - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MAX: Self = !0; } - doc_comment! { - "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! { - "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 } - } - doc_comment! { concat!("Converts a string slice in a given base to an integer. @@ -2548,7 +2519,7 @@ pub const fn count_ones(self) -> u32 { Basic usage: ``` -", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 0);", $EndFeature, " +", $Feature, "assert_eq!(", stringify!($SelfT), "::MAX.count_zeros(), 0);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_math", since = "1.32.0")] @@ -2566,7 +2537,7 @@ pub const fn count_zeros(self) -> u32 { Basic usage: ``` -", $Feature, "let n = ", stringify!($SelfT), "::max_value() >> 2; +", $Feature, "let n = ", stringify!($SelfT), "::MAX >> 2; assert_eq!(n.leading_zeros(), 2);", $EndFeature, " ```"), @@ -2608,7 +2579,7 @@ pub const fn trailing_zeros(self) -> u32 { ``` ", $Feature, "#![feature(leading_trailing_ones)] -let n = !(", stringify!($SelfT), "::max_value() >> 2); +let n = !(", stringify!($SelfT), "::MAX >> 2); assert_eq!(n.leading_ones(), 2);", $EndFeature, " ```"), @@ -2882,9 +2853,9 @@ pub const fn to_le(self) -> Self { Basic usage: ``` -", $Feature, "assert_eq!((", stringify!($SelfT), "::max_value() - 2).checked_add(1), ", -"Some(", stringify!($SelfT), "::max_value() - 1)); -assert_eq!((", stringify!($SelfT), "::max_value() - 2).checked_add(3), None);", $EndFeature, " +", $Feature, "assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(1), ", +"Some(", stringify!($SelfT), "::MAX - 1)); +assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] @@ -2930,7 +2901,7 @@ pub const fn checked_sub(self, rhs: Self) -> Option { ``` ", $Feature, "assert_eq!(5", stringify!($SelfT), ".checked_mul(1), Some(5)); -assert_eq!(", stringify!($SelfT), "::max_value().checked_mul(2), None);", $EndFeature, " +assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(2), None);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] @@ -3130,7 +3101,7 @@ pub const fn checked_shr(self, rhs: u32) -> Option { ``` ", $Feature, "assert_eq!(2", stringify!($SelfT), ".checked_pow(5), Some(32)); -assert_eq!(", stringify!($SelfT), "::max_value().checked_pow(2), None);", $EndFeature, " +assert_eq!(", stringify!($SelfT), "::MAX.checked_pow(2), None);", $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")] @@ -3214,8 +3185,7 @@ pub const fn saturating_sub(self, rhs: Self) -> Self { Basic usage: ``` -", $Feature, "use std::", stringify!($SelfT), "; - +", $Feature, " assert_eq!(2", stringify!($SelfT), ".saturating_mul(10), 20); assert_eq!((", stringify!($SelfT), "::MAX).saturating_mul(10), ", stringify!($SelfT), "::MAX);", $EndFeature, " @@ -3242,8 +3212,7 @@ pub const fn saturating_mul(self, rhs: Self) -> Self { Basic usage: ``` -", $Feature, "use std::", stringify!($SelfT), "; - +", $Feature, " assert_eq!(4", stringify!($SelfT), ".saturating_pow(3), 64); assert_eq!(", stringify!($SelfT), "::MAX.saturating_pow(2), ", stringify!($SelfT), "::MAX);", $EndFeature, " @@ -3271,7 +3240,7 @@ pub const fn saturating_pow(self, exp: u32) -> Self { ``` ", $Feature, "assert_eq!(200", stringify!($SelfT), ".wrapping_add(55), 255); -assert_eq!(200", stringify!($SelfT), ".wrapping_add(", stringify!($SelfT), "::max_value()), 199);", +assert_eq!(200", stringify!($SelfT), ".wrapping_add(", stringify!($SelfT), "::MAX), 199);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] @@ -3294,7 +3263,7 @@ pub const fn wrapping_add(self, rhs: Self) -> Self { ``` ", $Feature, "assert_eq!(100", stringify!($SelfT), ".wrapping_sub(100), 0); -assert_eq!(100", stringify!($SelfT), ".wrapping_sub(", stringify!($SelfT), "::max_value()), 101);", +assert_eq!(100", stringify!($SelfT), ".wrapping_sub(", stringify!($SelfT), "::MAX), 101);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] @@ -3582,8 +3551,7 @@ pub const fn wrapping_pow(self, mut exp: u32) -> Self { Basic usage ``` -", $Feature, "use std::", stringify!($SelfT), "; - +", $Feature, " assert_eq!(5", stringify!($SelfT), ".overflowing_add(2), (7, false)); assert_eq!(", stringify!($SelfT), "::MAX.overflowing_add(1), (0, true));", $EndFeature, " ```"), @@ -3610,8 +3578,7 @@ pub const fn overflowing_add(self, rhs: Self) -> (Self, bool) { Basic usage ``` -", $Feature, "use std::", stringify!($SelfT), "; - +", $Feature, " assert_eq!(5", stringify!($SelfT), ".overflowing_sub(2), (3, false)); assert_eq!(0", stringify!($SelfT), ".overflowing_sub(1), (", stringify!($SelfT), "::MAX, true));", $EndFeature, " @@ -4083,7 +4050,7 @@ pub const fn next_power_of_two(self) -> Self { ", $Feature, "assert_eq!(2", stringify!($SelfT), ".checked_next_power_of_two(), Some(2)); assert_eq!(3", stringify!($SelfT), ".checked_next_power_of_two(), Some(4)); -assert_eq!(", stringify!($SelfT), "::max_value().checked_next_power_of_two(), None);", +assert_eq!(", stringify!($SelfT), "::MAX.checked_next_power_of_two(), None);", $EndFeature, " ```"), #[inline] @@ -4108,7 +4075,7 @@ pub const fn checked_next_power_of_two(self) -> Option { ", $Feature, " assert_eq!(2", stringify!($SelfT), ".wrapping_next_power_of_two(), 2); assert_eq!(3", stringify!($SelfT), ".wrapping_next_power_of_two(), 4); -assert_eq!(", stringify!($SelfT), "::max_value().wrapping_next_power_of_two(), 0);", +assert_eq!(", stringify!($SelfT), "::MAX.wrapping_next_power_of_two(), 0);", $EndFeature, " ```"), #[unstable(feature = "wrapping_next_power_of_two", issue = "32463", @@ -4304,6 +4271,34 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), unsafe { mem::transmute(bytes) } } } + + 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 } + } } } @@ -4876,7 +4871,6 @@ impl usize { /// /// ``` /// use std::num::FpCategory; -/// use std::f32; /// /// let num = 12.4_f32; /// let inf = f32::INFINITY;