Auto merge of #68952 - faern:stabilize-assoc-int-consts, r=dtolnay

Stabilize assoc_int_consts associated int/float constants

The next step in RFC https://github.com/rust-lang/rfcs/pull/2700 (tracking issue #68490). Stabilizing the associated constants that were added in #68325.

* Stabilize all constants under the `assoc_int_consts` feature flag.
* Update documentation on old constants to say they are soft-deprecated and the new ones should be preferred.
* Update documentation examples to use new constants.
* Remove `uint_macro` and use `int_macro` for all integer types since the macros were identical anyway.

r? @LukasKalbertodt
This commit is contained in:
bors 2020-03-04 07:29:32 +00:00
commit 7a3700c371
22 changed files with 263 additions and 242 deletions

View File

@ -141,7 +141,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]
@ -159,10 +158,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"]

View File

@ -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 wont 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;
///

View File

@ -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 wont 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;

View File

@ -1,6 +1,9 @@
//! The 128-bit signed integer type.
//!
//! *[See also the `i128` primitive type](../../std/primitive.i128.html).*
//!
//! Although using these constants wont cause compilation warnings,
//! new code should use the associated constants directly on the primitive type.
#![stable(feature = "i128", since = "1.26.0")]

View File

@ -1,6 +1,9 @@
//! The 16-bit signed integer type.
//!
//! *[See also the `i16` primitive type](../../std/primitive.i16.html).*
//!
//! Although using these constants wont cause compilation warnings,
//! new code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]

View File

@ -1,6 +1,9 @@
//! The 32-bit signed integer type.
//!
//! *[See also the `i32` primitive type](../../std/primitive.i32.html).*
//!
//! Although using these constants wont cause compilation warnings,
//! new code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]

View File

@ -1,6 +1,9 @@
//! The 64-bit signed integer type.
//!
//! *[See also the `i64` primitive type](../../std/primitive.i64.html).*
//!
//! Although using these constants wont cause compilation warnings,
//! new code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]

View File

@ -1,6 +1,9 @@
//! The 8-bit signed integer type.
//!
//! *[See also the `i8` primitive type](../../std/primitive.i8.html).*
//!
//! Although using these constants wont cause compilation warnings,
//! new code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]

View File

@ -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();
}
)
}

View File

@ -1,6 +1,9 @@
//! The pointer-sized signed integer type.
//!
//! *[See also the `isize` primitive type](../../std/primitive.isize.html).*
//!
//! Although using these constants wont cause compilation warnings,
//! new code should use the associated constants directly on the primitive type.
#![stable(feature = "rust1", since = "1.0.0")]

View File

@ -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 @@ $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.
@ -369,7 +345,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")]
@ -706,8 +682,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")]
@ -731,8 +707,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")]
@ -756,8 +732,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")]
@ -781,8 +757,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, "
```"),
@ -811,8 +787,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")]
@ -838,8 +814,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);",
@ -869,8 +844,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);
@ -897,8 +870,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, "
@ -969,8 +941,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, "
@ -997,7 +968,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, "
```"),
@ -1039,10 +1010,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, "
```"),
@ -1066,10 +1037,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")]
@ -1094,10 +1065,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, "
```"),
@ -1121,10 +1092,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, "
```"),
@ -1149,8 +1120,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);",
@ -1182,8 +1152,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);",
@ -1213,8 +1182,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")]
@ -1237,8 +1206,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")]
@ -1409,8 +1378,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")]
@ -1500,8 +1469,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, "
```"),
@ -1572,8 +1541,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, "
@ -1600,8 +1568,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, "
@ -1658,8 +1625,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));",
@ -1694,8 +1660,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));
@ -1729,8 +1693,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, "
@ -1765,8 +1728,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));
```"),
@ -1797,8 +1758,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, "
@ -1884,8 +1843,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")]
@ -2083,10 +2042,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
@ -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 wont 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 wont 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 @@ 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.
@ -2548,7 +2519,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")]
@ -2566,7 +2537,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, "
```"),
@ -2608,7 +2579,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, "
```"),
@ -2882,9 +2853,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")]
@ -2930,7 +2901,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")]
@ -3130,7 +3101,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")]
#[rustc_const_unstable(feature = "const_int_pow", issue = "53718")]
@ -3214,8 +3185,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, "
@ -3242,8 +3212,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, "
@ -3271,7 +3240,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")]
@ -3294,7 +3263,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")]
@ -3582,8 +3551,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, "
```"),
@ -3610,8 +3578,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, "
@ -4083,7 +4050,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]
@ -4108,7 +4075,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",
@ -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 wont 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 wont 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;

View File

@ -1,6 +1,9 @@
//! The 128-bit unsigned integer type.
//!
//! *[See also the `u128` primitive type](../../std/primitive.u128.html).*
//!
//! Although using these constants wont 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")] }

View File

@ -1,7 +1,10 @@
//! The 16-bit unsigned integer type.
//!
//! *[See also the `u16` primitive type](../../std/primitive.u16.html).*
//!
//! Although using these constants wont 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 }

View File

@ -1,7 +1,10 @@
//! The 32-bit unsigned integer type.
//!
//! *[See also the `u32` primitive type](../../std/primitive.u32.html).*
//!
//! Although using these constants wont 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 }

View File

@ -1,7 +1,10 @@
//! The 64-bit unsigned integer type.
//!
//! *[See also the `u64` primitive type](../../std/primitive.u64.html).*
//!
//! Although using these constants wont 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 }

View File

@ -1,7 +1,10 @@
//! The 8-bit unsigned integer type.
//!
//! *[See also the `u8` primitive type](../../std/primitive.u8.html).*
//!
//! Although using these constants wont 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 }

View File

@ -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();
)
}

View File

@ -1,7 +1,10 @@
//! The pointer-sized unsigned integer type.
//!
//! *[See also the `usize` primitive type](../../std/primitive.usize.html).*
//!
//! Although using these constants wont 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 }

View File

@ -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 wont 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)]

View File

@ -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 wont 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)]

View File

@ -236,7 +236,6 @@
#![feature(arbitrary_self_types)]
#![feature(array_error_internals)]
#![feature(asm)]
#![feature(assoc_int_consts)]
#![feature(associated_type_bounds)]
#![feature(atomic_mut_ptr)]
#![feature(box_syntax)]

View File

@ -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.