diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 12647fae9004e..1cd3e413ecc34 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -138,7 +138,6 @@ #![feature(associated_type_bounds)] #![feature(const_type_id)] #![feature(const_caller_location)] -#![feature(assoc_int_consts)] #![cfg_attr(not(bootstrap), feature(no_niche))] // rust-lang/rust#68303 #[prelude_import] @@ -156,10 +155,6 @@ mod internal_macros; #[macro_use] mod int_macros; -#[path = "num/uint_macros.rs"] -#[macro_use] -mod uint_macros; - #[path = "num/i128.rs"] pub mod i128; #[path = "num/i16.rs"] diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index da8dd9acd9f48..3a641ae94a443 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -4,6 +4,9 @@ //! *[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")] @@ -14,17 +17,21 @@ 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. #[stable(feature = "rust1", since = "1.0.0")] 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. #[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. #[stable(feature = "rust1", since = "1.0.0")] 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. /// @@ -33,36 +40,46 @@ pub const DIGITS: u32 = f32::DIGITS; pub const EPSILON: f32 = f32::EPSILON; /// Smallest finite `f32` value. +/// Use [`f32::MIN`](../../std/primitive.f32.html#associatedconstant.MIN) instead. #[stable(feature = "rust1", since = "1.0.0")] pub const MIN: f32 = f32::MIN; /// Smallest positive normal `f32` value. +/// Use [`f32::MIN_POSITIVE`](../../std/primitive.f32.html#associatedconstant.MIN_POSITIVE) instead. #[stable(feature = "rust1", since = "1.0.0")] pub const MIN_POSITIVE: f32 = f32::MIN_POSITIVE; /// Largest finite `f32` value. +/// Use [`f32::MAX`](../../std/primitive.f32.html#associatedconstant.MAX) instead. #[stable(feature = "rust1", since = "1.0.0")] 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. #[stable(feature = "rust1", since = "1.0.0")] 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. #[stable(feature = "rust1", since = "1.0.0")] 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. #[stable(feature = "rust1", since = "1.0.0")] 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. #[stable(feature = "rust1", since = "1.0.0")] pub const MAX_10_EXP: i32 = f32::MAX_10_EXP; /// Not a Number (NaN). +/// Use [`f32::NAN`](../../std/primitive.f32.html#associatedconstant.NAN) instead. #[stable(feature = "rust1", since = "1.0.0")] pub const NAN: f32 = f32::NAN; /// Infinity (∞). +/// Use [`f32::INFINITY`](../../std/primitive.f32.html#associatedconstant.INFINITY) instead. #[stable(feature = "rust1", since = "1.0.0")] pub const INFINITY: f32 = f32::INFINITY; /// Negative infinity (−∞). +/// Use [`f32::NEG_INFINITY`](../../std/primitive.f32.html#associatedconstant.NEG_INFINITY) instead. #[stable(feature = "rust1", since = "1.0.0")] pub const NEG_INFINITY: f32 = f32::NEG_INFINITY; @@ -154,15 +171,15 @@ pub mod consts { #[cfg(not(test))] impl f32 { /// The radix or base of the internal representation of `f32`. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const RADIX: u32 = 2; /// Number of significant digits in base 2. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MANTISSA_DIGITS: u32 = 24; /// Approximate number of significant digits in base 10. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const DIGITS: u32 = 6; /// [Machine epsilon] value for `f32`. @@ -170,48 +187,46 @@ impl f32 { /// This is the difference between `1.0` and the next larger representable number. /// /// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const EPSILON: f32 = 1.19209290e-07_f32; /// Smallest finite `f32` value. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN: f32 = -3.40282347e+38_f32; /// Smallest positive normal `f32` value. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32; /// Largest finite `f32` value. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MAX: f32 = 3.40282347e+38_f32; /// One greater than the minimum possible normal power of 2 exponent. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN_EXP: i32 = -125; /// Maximum possible power of 2 exponent. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MAX_EXP: i32 = 128; /// Minimum possible normal power of 10 exponent. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN_10_EXP: i32 = -37; /// Maximum possible power of 10 exponent. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MAX_10_EXP: i32 = 38; /// Not a Number (NaN). - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const NAN: f32 = 0.0_f32 / 0.0_f32; /// Infinity (∞). - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const INFINITY: f32 = 1.0_f32 / 0.0_f32; /// Negative infinity (-∞). - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const NEG_INFINITY: f32 = -1.0_f32 / 0.0_f32; /// Returns `true` if this value is `NaN`. /// /// ``` - /// use std::f32; - /// /// let nan = f32::NAN; /// let f = 7.0_f32; /// @@ -236,8 +251,6 @@ impl f32 { /// `false` otherwise. /// /// ``` - /// use std::f32; - /// /// let f = 7.0f32; /// let inf = f32::INFINITY; /// let neg_inf = f32::NEG_INFINITY; @@ -258,8 +271,6 @@ impl f32 { /// Returns `true` if this number is neither infinite nor `NaN`. /// /// ``` - /// use std::f32; - /// /// let f = 7.0f32; /// let inf = f32::INFINITY; /// let neg_inf = f32::NEG_INFINITY; @@ -283,8 +294,6 @@ impl f32 { /// [subnormal], or `NaN`. /// /// ``` - /// use std::f32; - /// /// let min = f32::MIN_POSITIVE; // 1.17549435e-38f32 /// let max = f32::MAX; /// let lower_than_min = 1.0e-40_f32; @@ -312,7 +321,6 @@ impl f32 { /// /// ``` /// use std::num::FpCategory; - /// use std::f32; /// /// let num = 12.4_f32; /// let inf = f32::INFINITY; @@ -372,8 +380,6 @@ impl f32 { /// Takes the reciprocal (inverse) of a number, `1/x`. /// /// ``` - /// use std::f32; - /// /// let x = 2.0_f32; /// let abs_difference = (x.recip() - (1.0 / x)).abs(); /// @@ -388,7 +394,7 @@ impl f32 { /// Converts radians to degrees. /// /// ``` - /// use std::f32::{self, consts}; + /// use std::f32::consts; /// /// let angle = consts::PI; /// @@ -407,7 +413,7 @@ impl f32 { /// Converts degrees to radians. /// /// ``` - /// use std::f32::{self, consts}; + /// use std::f32::consts; /// /// let angle = 180.0f32; /// diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index a6081f184ab22..121ed149294a3 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -4,6 +4,9 @@ //! *[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")] @@ -14,17 +17,21 @@ 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. #[stable(feature = "rust1", since = "1.0.0")] 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. #[stable(feature = "rust1", since = "1.0.0")] 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. #[stable(feature = "rust1", since = "1.0.0")] 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. /// @@ -33,36 +40,46 @@ pub const DIGITS: u32 = f64::DIGITS; pub const EPSILON: f64 = f64::EPSILON; /// Smallest finite `f64` value. +/// Use [`f64::MIN`](../../std/primitive.f64.html#associatedconstant.MIN) instead. #[stable(feature = "rust1", since = "1.0.0")] pub const MIN: f64 = f64::MIN; /// Smallest positive normal `f64` value. +/// Use [`f64::MIN_POSITIVE`](../../std/primitive.f64.html#associatedconstant.MIN_POSITIVE) instead. #[stable(feature = "rust1", since = "1.0.0")] pub const MIN_POSITIVE: f64 = f64::MIN_POSITIVE; /// Largest finite `f64` value. +/// Use [`f64::MAX`](../../std/primitive.f64.html#associatedconstant.MAX) instead. #[stable(feature = "rust1", since = "1.0.0")] 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. #[stable(feature = "rust1", since = "1.0.0")] 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. #[stable(feature = "rust1", since = "1.0.0")] 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. #[stable(feature = "rust1", since = "1.0.0")] 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. #[stable(feature = "rust1", since = "1.0.0")] pub const MAX_10_EXP: i32 = f64::MAX_10_EXP; /// Not a Number (NaN). +/// Use [`f64::NAN`](../../std/primitive.f64.html#associatedconstant.NAN) instead. #[stable(feature = "rust1", since = "1.0.0")] pub const NAN: f64 = f64::NAN; /// Infinity (∞). +/// Use [`f64::INFINITY`](../../std/primitive.f64.html#associatedconstant.INFINITY) instead. #[stable(feature = "rust1", since = "1.0.0")] pub const INFINITY: f64 = f64::INFINITY; /// Negative infinity (−∞). +/// Use [`f64::NEG_INFINITY`](../../std/primitive.f64.html#associatedconstant.NEG_INFINITY) instead. #[stable(feature = "rust1", since = "1.0.0")] pub const NEG_INFINITY: f64 = f64::NEG_INFINITY; @@ -154,14 +171,14 @@ pub mod consts { #[cfg(not(test))] impl f64 { /// The radix or base of the internal representation of `f64`. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const RADIX: u32 = 2; /// Number of significant digits in base 2. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MANTISSA_DIGITS: u32 = 53; /// Approximate number of significant digits in base 10. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const DIGITS: u32 = 15; /// [Machine epsilon] value for `f64`. @@ -169,48 +186,46 @@ impl f64 { /// This is the difference between `1.0` and the next larger representable number. /// /// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const EPSILON: f64 = 2.2204460492503131e-16_f64; /// Smallest finite `f64` value. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN: f64 = -1.7976931348623157e+308_f64; /// Smallest positive normal `f64` value. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308_f64; /// Largest finite `f64` value. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MAX: f64 = 1.7976931348623157e+308_f64; /// One greater than the minimum possible normal power of 2 exponent. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN_EXP: i32 = -1021; /// Maximum possible power of 2 exponent. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MAX_EXP: i32 = 1024; /// Minimum possible normal power of 10 exponent. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MIN_10_EXP: i32 = -307; /// Maximum possible power of 10 exponent. - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const MAX_10_EXP: i32 = 308; /// Not a Number (NaN). - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const NAN: f64 = 0.0_f64 / 0.0_f64; /// Infinity (∞). - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const INFINITY: f64 = 1.0_f64 / 0.0_f64; /// Negative infinity (-∞). - #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + #[stable(feature = "assoc_int_consts", since = "1.43.0")] pub const NEG_INFINITY: f64 = -1.0_f64 / 0.0_f64; /// Returns `true` if this value is `NaN`. /// /// ``` - /// use std::f64; - /// /// let nan = f64::NAN; /// let f = 7.0_f64; /// @@ -235,8 +250,6 @@ impl f64 { /// `false` otherwise. /// /// ``` - /// use std::f64; - /// /// let f = 7.0f64; /// let inf = f64::INFINITY; /// let neg_inf = f64::NEG_INFINITY; @@ -257,8 +270,6 @@ impl f64 { /// Returns `true` if this number is neither infinite nor `NaN`. /// /// ``` - /// use std::f64; - /// /// let f = 7.0f64; /// let inf: f64 = f64::INFINITY; /// let neg_inf: f64 = f64::NEG_INFINITY; @@ -282,8 +293,6 @@ impl f64 { /// [subnormal], or `NaN`. /// /// ``` - /// use std::f64; - /// /// let min = f64::MIN_POSITIVE; // 2.2250738585072014e-308f64 /// let max = f64::MAX; /// let lower_than_min = 1.0e-308_f64; @@ -311,7 +320,6 @@ impl f64 { /// /// ``` /// use std::num::FpCategory; - /// use std::f64; /// /// let num = 12.4_f64; /// let inf = f64::INFINITY; diff --git a/src/libcore/num/i128.rs b/src/libcore/num/i128.rs index 564ed598a882c..08cb795946868 100644 --- a/src/libcore/num/i128.rs +++ b/src/libcore/num/i128.rs @@ -1,6 +1,9 @@ //! 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 44d6aaef25ba0..288eaceba59d6 100644 --- a/src/libcore/num/i16.rs +++ b/src/libcore/num/i16.rs @@ -1,6 +1,9 @@ //! 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 90a5f89195e31..0e1a2ec56ccb2 100644 --- a/src/libcore/num/i32.rs +++ b/src/libcore/num/i32.rs @@ -1,6 +1,9 @@ //! 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 04a8a9d757915..27f7092710b34 100644 --- a/src/libcore/num/i64.rs +++ b/src/libcore/num/i64.rs @@ -1,6 +1,9 @@ //! 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 5a52a967cf96d..e84b421e1a444 100644 --- a/src/libcore/num/i8.rs +++ b/src/libcore/num/i8.rs @@ -1,6 +1,9 @@ //! 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 5c59fe25f6483..b68a09e113180 100644 --- a/src/libcore/num/int_macros.rs +++ b/src/libcore/num/int_macros.rs @@ -1,13 +1,27 @@ #![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]) => ( - /// The smallest value that can be represented by this integer type. - #[$attr] - pub const MIN: $T = $T::min_value(); - /// The largest value that can be represented by this integer type. - #[$attr] - pub const MAX: $T = $T::max_value(); + 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."), + #[$attr] + pub const MIN: $T = $T::min_value(); + } + + 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."), + #[$attr] + pub const MAX: $T = $T::max_value(); + } ) } diff --git a/src/libcore/num/isize.rs b/src/libcore/num/isize.rs index 143f8b3b272d6..0dcfa4a2bd134 100644 --- a/src/libcore/num/isize.rs +++ b/src/libcore/num/isize.rs @@ -1,6 +1,9 @@ //! 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 471ab96662249..50d967dba6338 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -257,11 +257,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; } @@ -273,36 +272,13 @@ $EndFeature, " 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. @@ -360,7 +336,7 @@ $EndFeature, " 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")] @@ -697,8 +673,8 @@ 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);", +"::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")] @@ -722,8 +698,8 @@ Basic usage: ``` ", $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")] @@ -747,8 +723,8 @@ Basic usage: ``` ", $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")] @@ -772,8 +748,8 @@ Basic usage: ``` ", $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, " ```"), @@ -802,8 +778,8 @@ Basic usage: ``` 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")] @@ -829,8 +805,7 @@ assert_eq!((1", stringify!($SelfT), ").checked_div_euclid(0), None); 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);", @@ -860,8 +835,6 @@ if `rhs == 0` or the division results in overflow. 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); @@ -888,8 +861,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.checked_rem_euclid(-1), None); 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, " @@ -960,8 +932,7 @@ $EndFeature, " 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, " @@ -988,7 +959,7 @@ Basic usage: ``` ", $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, " ```"), @@ -1029,10 +1000,10 @@ Basic usage: ``` ", $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, " ```"), @@ -1056,10 +1027,10 @@ Basic usage: ``` ", $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")] @@ -1084,10 +1055,10 @@ Basic usage: ", $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, " ```"), @@ -1111,10 +1082,10 @@ Basic usage: ", $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, " ```"), @@ -1139,8 +1110,7 @@ numeric bounds instead of overflowing. 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);", @@ -1172,8 +1142,7 @@ saturating at the numeric bounds instead of overflowing. 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);", @@ -1202,8 +1171,8 @@ Basic usage: ``` ", $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")] @@ -1226,8 +1195,8 @@ Basic usage: ``` ", $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")] @@ -1398,8 +1367,8 @@ Basic usage: ``` ", $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")] @@ -1489,8 +1458,8 @@ Basic usage: ``` ", $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, " ```"), @@ -1560,8 +1529,7 @@ occur. If an overflow would have occurred then the wrapped value is returned. 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, " @@ -1588,8 +1556,7 @@ would occur. If an overflow would have occurred then the wrapped value is return 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, " @@ -1646,8 +1613,7 @@ This function will panic if `rhs` is 0. 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));", @@ -1682,8 +1648,6 @@ This function will panic if `rhs` is 0. 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)); @@ -1717,8 +1681,7 @@ This function will panic if `rhs` is 0. 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, " @@ -1753,8 +1716,6 @@ This function will panic if `rhs` is 0. 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)); ```"), @@ -1785,8 +1746,6 @@ minimum value will be returned again and `true` will be returned for an overflow 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, " @@ -1872,8 +1831,8 @@ Basic usage: ``` ", $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")] @@ -2069,10 +2028,10 @@ assert_eq!((-a).rem_euclid(-b), 1); # 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 @@ -2353,6 +2312,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 + } + } } } @@ -2435,10 +2426,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; } @@ -2450,32 +2440,13 @@ Basic usage: 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. @@ -2534,7 +2505,7 @@ assert_eq!(n.count_ones(), 3);", $EndFeature, " 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")] @@ -2552,7 +2523,7 @@ Basic usage: Basic usage: ``` -", $Feature, "let n = ", stringify!($SelfT), "::max_value() >> 2; +", $Feature, "let n = ", stringify!($SelfT), "::MAX >> 2; assert_eq!(n.leading_zeros(), 2);", $EndFeature, " ```"), @@ -2594,7 +2565,7 @@ Basic usage: ``` ", $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, " ```"), @@ -2868,9 +2839,9 @@ if overflow occurred. 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")] @@ -2916,7 +2887,7 @@ Basic usage: ``` ", $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")] @@ -3116,7 +3087,7 @@ Basic usage: ``` ", $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")] #[must_use = "this returns the result of the operation, \ @@ -3199,8 +3170,7 @@ saturating at the numeric bounds instead of overflowing. 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, " @@ -3227,8 +3197,7 @@ saturating at the numeric bounds instead of overflowing. 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, " @@ -3255,7 +3224,7 @@ Basic usage: ``` ", $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")] @@ -3278,7 +3247,7 @@ Basic usage: ``` ", $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")] @@ -3565,8 +3534,7 @@ have occurred then the wrapped value is returned. 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, " ```"), @@ -3593,8 +3561,7 @@ have occurred then the wrapped value is returned. 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, " @@ -4062,7 +4029,7 @@ Basic usage: ", $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] @@ -4086,7 +4053,7 @@ Basic usage: ", $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", @@ -4281,6 +4248,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 } + } } } @@ -4852,7 +4847,6 @@ impl usize { /// /// ``` /// use std::num::FpCategory; -/// use std::f32; /// /// let num = 12.4_f32; /// let inf = f32::INFINITY; diff --git a/src/libcore/num/u128.rs b/src/libcore/num/u128.rs index 7d1aa664de30c..dd45ff141539f 100644 --- a/src/libcore/num/u128.rs +++ b/src/libcore/num/u128.rs @@ -1,6 +1,9 @@ //! 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")] -uint_module! { u128, #[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 34f80abaecc05..738071643b639 100644 --- a/src/libcore/num/u16.rs +++ b/src/libcore/num/u16.rs @@ -1,7 +1,10 @@ //! 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")] -uint_module! { u16 } +int_module! { u16 } diff --git a/src/libcore/num/u32.rs b/src/libcore/num/u32.rs index 5fd486f546608..9800c9099748f 100644 --- a/src/libcore/num/u32.rs +++ b/src/libcore/num/u32.rs @@ -1,7 +1,10 @@ //! 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")] -uint_module! { u32 } +int_module! { u32 } diff --git a/src/libcore/num/u64.rs b/src/libcore/num/u64.rs index 044d238aea9be..fb686c396f033 100644 --- a/src/libcore/num/u64.rs +++ b/src/libcore/num/u64.rs @@ -1,7 +1,10 @@ //! 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")] -uint_module! { u64 } +int_module! { u64 } diff --git a/src/libcore/num/u8.rs b/src/libcore/num/u8.rs index 6747e6a0f6c24..c03cbdda25dbb 100644 --- a/src/libcore/num/u8.rs +++ b/src/libcore/num/u8.rs @@ -1,7 +1,10 @@ //! 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")] -uint_module! { u8 } +int_module! { u8 } diff --git a/src/libcore/num/uint_macros.rs b/src/libcore/num/uint_macros.rs deleted file mode 100644 index a94b541ddb907..0000000000000 --- a/src/libcore/num/uint_macros.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![doc(hidden)] - -macro_rules! uint_module { - ($T:ident) => (uint_module!($T, #[stable(feature = "rust1", since = "1.0.0")]);); - ($T:ident, #[$attr:meta]) => ( - /// The smallest value that can be represented by this integer type. - #[$attr] - pub const MIN: $T = $T::min_value(); - /// The largest value that can be represented by this integer type. - #[$attr] - pub const MAX: $T = $T::max_value(); - ) -} diff --git a/src/libcore/num/usize.rs b/src/libcore/num/usize.rs index e3a5239d908dc..a893041615244 100644 --- a/src/libcore/num/usize.rs +++ b/src/libcore/num/usize.rs @@ -1,7 +1,10 @@ //! 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")] -uint_module! { usize } +int_module! { usize } diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 941ea6a767c57..20425aea8d517 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -4,6 +4,9 @@ //! *[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)] diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index d89b38e1a0035..a1128a589a64a 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -4,6 +4,9 @@ //! *[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)] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index f9c9f224730da..50f05d0c7f9d7 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -237,7 +237,6 @@ #![feature(arbitrary_self_types)] #![feature(array_error_internals)] #![feature(asm)] -#![feature(assoc_int_consts)] #![feature(associated_type_bounds)] #![feature(box_syntax)] #![feature(c_variadic)] diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs index d4b41e11c0e82..adad90f56d1cf 100644 --- a/src/libstd/primitive_docs.rs +++ b/src/libstd/primitive_docs.rs @@ -771,7 +771,7 @@ mod prim_tuple {} #[doc(primitive = "f32")] /// The 32-bit floating point type. /// -/// *[See also the `std::f32` module](f32/index.html).* +/// *[See also the `std::f32::consts` module](f32/consts/index.html).* /// #[stable(feature = "rust1", since = "1.0.0")] mod prim_f32 {} @@ -780,7 +780,7 @@ mod prim_f32 {} // /// The 64-bit floating point type. /// -/// *[See also the `std::f64` module](f64/index.html).* +/// *[See also the `std::f64::consts` module](f64/consts/index.html).* /// #[stable(feature = "rust1", since = "1.0.0")] mod prim_f64 {} @@ -788,80 +788,60 @@ mod prim_f64 {} #[doc(primitive = "i8")] // /// The 8-bit signed integer type. -/// -/// *[See also the `std::i8` module](i8/index.html).* #[stable(feature = "rust1", since = "1.0.0")] mod prim_i8 {} #[doc(primitive = "i16")] // /// The 16-bit signed integer type. -/// -/// *[See also the `std::i16` module](i16/index.html).* #[stable(feature = "rust1", since = "1.0.0")] mod prim_i16 {} #[doc(primitive = "i32")] // /// The 32-bit signed integer type. -/// -/// *[See also the `std::i32` module](i32/index.html).* #[stable(feature = "rust1", since = "1.0.0")] mod prim_i32 {} #[doc(primitive = "i64")] // /// The 64-bit signed integer type. -/// -/// *[See also the `std::i64` module](i64/index.html).* #[stable(feature = "rust1", since = "1.0.0")] mod prim_i64 {} #[doc(primitive = "i128")] // /// The 128-bit signed integer type. -/// -/// *[See also the `std::i128` module](i128/index.html).* #[stable(feature = "i128", since = "1.26.0")] mod prim_i128 {} #[doc(primitive = "u8")] // /// The 8-bit unsigned integer type. -/// -/// *[See also the `std::u8` module](u8/index.html).* #[stable(feature = "rust1", since = "1.0.0")] mod prim_u8 {} #[doc(primitive = "u16")] // /// The 16-bit unsigned integer type. -/// -/// *[See also the `std::u16` module](u16/index.html).* #[stable(feature = "rust1", since = "1.0.0")] mod prim_u16 {} #[doc(primitive = "u32")] // /// The 32-bit unsigned integer type. -/// -/// *[See also the `std::u32` module](u32/index.html).* #[stable(feature = "rust1", since = "1.0.0")] mod prim_u32 {} #[doc(primitive = "u64")] // /// The 64-bit unsigned integer type. -/// -/// *[See also the `std::u64` module](u64/index.html).* #[stable(feature = "rust1", since = "1.0.0")] mod prim_u64 {} #[doc(primitive = "u128")] // /// The 128-bit unsigned integer type. -/// -/// *[See also the `std::u128` module](u128/index.html).* #[stable(feature = "i128", since = "1.26.0")] mod prim_u128 {} @@ -869,8 +849,6 @@ mod prim_u128 {} // /// The pointer-sized signed integer type. /// -/// *[See also the `std::isize` module](isize/index.html).* -/// /// The size of this primitive is how many bytes it takes to reference any /// location in memory. For example, on a 32 bit target, this is 4 bytes /// and on a 64 bit target, this is 8 bytes. @@ -881,8 +859,6 @@ mod prim_isize {} // /// The pointer-sized unsigned integer type. /// -/// *[See also the `std::usize` module](usize/index.html).* -/// /// The size of this primitive is how many bytes it takes to reference any /// location in memory. For example, on a 32 bit target, this is 4 bytes /// and on a 64 bit target, this is 8 bytes.