From b5ff8064a4fe5b2bc70ee209b19d129b8ffc3ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Fri, 17 Jan 2020 22:16:52 +0100 Subject: [PATCH 1/8] Add MIN/MAX associated constants to the integer types --- src/libcore/num/mod.rs | 70 ++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 072966abf2c40..e717d0e42bb00 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -245,42 +245,54 @@ macro_rules! int_impl { $reversed:expr, $le_bytes:expr, $be_bytes:expr, $to_xe_bytes_doc:expr, $from_xe_bytes_doc:expr) => { doc_comment! { - concat!("Returns the smallest value that can be represented by this integer type. + concat!("The smallest value that can be represented by this integer type. # Examples Basic usage: ``` -", $Feature, "assert_eq!(", stringify!($SelfT), "::min_value(), ", stringify!($Min), ");", +", $Feature, "assert_eq!(", stringify!($SelfT), "::MIN, ", stringify!($Min), ");", $EndFeature, " ```"), - #[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 { - !0 ^ ((!0 as $UnsignedT) >> 1) as Self - } + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const MIN: Self = !0 ^ ((!0 as $UnsignedT) >> 1) as Self; } doc_comment! { - concat!("Returns the largest value that can be represented by this integer type. + concat!("The largest value that can be represented by this integer type. # Examples Basic usage: ``` -", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value(), ", stringify!($Max), ");", +", $Feature, "assert_eq!(", stringify!($SelfT), "::MAX, ", stringify!($Max), ");", $EndFeature, " ```"), + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + 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::min_value() + Self::MAX } } @@ -2342,38 +2354,50 @@ macro_rules! uint_impl { $reversed:expr, $le_bytes:expr, $be_bytes:expr, $to_xe_bytes_doc:expr, $from_xe_bytes_doc:expr) => { doc_comment! { - concat!("Returns the smallest value that can be represented by this integer type. + concat!("The smallest value that can be represented by this integer type. # Examples Basic usage: ``` -", $Feature, "assert_eq!(", stringify!($SelfT), "::min_value(), 0);", $EndFeature, " +", $Feature, "assert_eq!(", stringify!($SelfT), "::MIN, 0);", $EndFeature, " ```"), - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_promotable] - #[inline(always)] - #[rustc_const_stable(feature = "const_min_value", since = "1.32.0")] - pub const fn min_value() -> Self { 0 } + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const MIN: Self = 0; } doc_comment! { - concat!("Returns the largest value that can be represented by this integer type. + concat!("The largest value that can be represented by this integer type. # Examples Basic usage: ``` -", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value(), ", -stringify!($MaxV), ");", $EndFeature, " +", $Feature, "assert_eq!(", stringify!($SelfT), "::MAX, ", stringify!($MaxV), ");", +$EndFeature, " ```"), + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + 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 { !0 } + pub const fn max_value() -> Self { Self::MAX } } doc_comment! { From 22dcfa1d8d18687d7ca0b91974bce4202d3383e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Fri, 17 Jan 2020 20:39:15 +0100 Subject: [PATCH 2/8] Add relevant associated constants to the float types --- src/libcore/num/f32.rs | 82 ++++++++++++++++++++++++++++++++++-------- src/libcore/num/f64.rs | 81 +++++++++++++++++++++++++++++++++-------- 2 files changed, 135 insertions(+), 28 deletions(-) diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index 505484c2a49dc..da8dd9acd9f48 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -15,14 +15,14 @@ use crate::num::FpCategory; /// The radix or base of the internal representation of `f32`. #[stable(feature = "rust1", since = "1.0.0")] -pub const RADIX: u32 = 2; +pub const RADIX: u32 = f32::RADIX; /// Number of significant digits in base 2. #[stable(feature = "rust1", since = "1.0.0")] -pub const MANTISSA_DIGITS: u32 = 24; +pub const MANTISSA_DIGITS: u32 = f32::MANTISSA_DIGITS; /// Approximate number of significant digits in base 10. #[stable(feature = "rust1", since = "1.0.0")] -pub const DIGITS: u32 = 6; +pub const DIGITS: u32 = f32::DIGITS; /// [Machine epsilon] value for `f32`. /// @@ -30,41 +30,41 @@ pub const DIGITS: u32 = 6; /// /// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon #[stable(feature = "rust1", since = "1.0.0")] -pub const EPSILON: f32 = 1.1920929e-7_f32; +pub const EPSILON: f32 = f32::EPSILON; /// Smallest finite `f32` value. #[stable(feature = "rust1", since = "1.0.0")] -pub const MIN: f32 = -3.40282347e+38_f32; +pub const MIN: f32 = f32::MIN; /// Smallest positive normal `f32` value. #[stable(feature = "rust1", since = "1.0.0")] -pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32; +pub const MIN_POSITIVE: f32 = f32::MIN_POSITIVE; /// Largest finite `f32` value. #[stable(feature = "rust1", since = "1.0.0")] -pub const MAX: f32 = 3.40282347e+38_f32; +pub const MAX: f32 = f32::MAX; /// One greater than the minimum possible normal power of 2 exponent. #[stable(feature = "rust1", since = "1.0.0")] -pub const MIN_EXP: i32 = -125; +pub const MIN_EXP: i32 = f32::MIN_EXP; /// Maximum possible power of 2 exponent. #[stable(feature = "rust1", since = "1.0.0")] -pub const MAX_EXP: i32 = 128; +pub const MAX_EXP: i32 = f32::MAX_EXP; /// Minimum possible normal power of 10 exponent. #[stable(feature = "rust1", since = "1.0.0")] -pub const MIN_10_EXP: i32 = -37; +pub const MIN_10_EXP: i32 = f32::MIN_10_EXP; /// Maximum possible power of 10 exponent. #[stable(feature = "rust1", since = "1.0.0")] -pub const MAX_10_EXP: i32 = 38; +pub const MAX_10_EXP: i32 = f32::MAX_10_EXP; /// Not a Number (NaN). #[stable(feature = "rust1", since = "1.0.0")] -pub const NAN: f32 = 0.0_f32 / 0.0_f32; +pub const NAN: f32 = f32::NAN; /// Infinity (∞). #[stable(feature = "rust1", since = "1.0.0")] -pub const INFINITY: f32 = 1.0_f32 / 0.0_f32; +pub const INFINITY: f32 = f32::INFINITY; /// Negative infinity (−∞). #[stable(feature = "rust1", since = "1.0.0")] -pub const NEG_INFINITY: f32 = -1.0_f32 / 0.0_f32; +pub const NEG_INFINITY: f32 = f32::NEG_INFINITY; /// Basic mathematical constants. #[stable(feature = "rust1", since = "1.0.0")] @@ -153,6 +153,60 @@ pub mod consts { #[lang = "f32"] #[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")] + pub const RADIX: u32 = 2; + + /// Number of significant digits in base 2. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const MANTISSA_DIGITS: u32 = 24; + + /// Approximate number of significant digits in base 10. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const DIGITS: u32 = 6; + + /// [Machine epsilon] value for `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")] + pub const EPSILON: f32 = 1.19209290e-07_f32; + + /// Smallest finite `f32` value. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const MIN: f32 = -3.40282347e+38_f32; + /// Smallest positive normal `f32` value. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32; + /// Largest finite `f32` value. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + 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")] + pub const MIN_EXP: i32 = -125; + /// Maximum possible power of 2 exponent. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const MAX_EXP: i32 = 128; + + /// Minimum possible normal power of 10 exponent. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const MIN_10_EXP: i32 = -37; + /// Maximum possible power of 10 exponent. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const MAX_10_EXP: i32 = 38; + + /// Not a Number (NaN). + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const NAN: f32 = 0.0_f32 / 0.0_f32; + /// Infinity (∞). + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const INFINITY: f32 = 1.0_f32 / 0.0_f32; + /// Negative infinity (-∞). + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const NEG_INFINITY: f32 = -1.0_f32 / 0.0_f32; + /// Returns `true` if this value is `NaN`. /// /// ``` diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 8f3af42d25d80..a6081f184ab22 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -15,14 +15,14 @@ use crate::num::FpCategory; /// The radix or base of the internal representation of `f64`. #[stable(feature = "rust1", since = "1.0.0")] -pub const RADIX: u32 = 2; +pub const RADIX: u32 = f64::RADIX; /// Number of significant digits in base 2. #[stable(feature = "rust1", since = "1.0.0")] -pub const MANTISSA_DIGITS: u32 = 53; +pub const MANTISSA_DIGITS: u32 = f64::MANTISSA_DIGITS; /// Approximate number of significant digits in base 10. #[stable(feature = "rust1", since = "1.0.0")] -pub const DIGITS: u32 = 15; +pub const DIGITS: u32 = f64::DIGITS; /// [Machine epsilon] value for `f64`. /// @@ -30,41 +30,41 @@ pub const DIGITS: u32 = 15; /// /// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon #[stable(feature = "rust1", since = "1.0.0")] -pub const EPSILON: f64 = 2.2204460492503131e-16_f64; +pub const EPSILON: f64 = f64::EPSILON; /// Smallest finite `f64` value. #[stable(feature = "rust1", since = "1.0.0")] -pub const MIN: f64 = -1.7976931348623157e+308_f64; +pub const MIN: f64 = f64::MIN; /// Smallest positive normal `f64` value. #[stable(feature = "rust1", since = "1.0.0")] -pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308_f64; +pub const MIN_POSITIVE: f64 = f64::MIN_POSITIVE; /// Largest finite `f64` value. #[stable(feature = "rust1", since = "1.0.0")] -pub const MAX: f64 = 1.7976931348623157e+308_f64; +pub const MAX: f64 = f64::MAX; /// One greater than the minimum possible normal power of 2 exponent. #[stable(feature = "rust1", since = "1.0.0")] -pub const MIN_EXP: i32 = -1021; +pub const MIN_EXP: i32 = f64::MIN_EXP; /// Maximum possible power of 2 exponent. #[stable(feature = "rust1", since = "1.0.0")] -pub const MAX_EXP: i32 = 1024; +pub const MAX_EXP: i32 = f64::MAX_EXP; /// Minimum possible normal power of 10 exponent. #[stable(feature = "rust1", since = "1.0.0")] -pub const MIN_10_EXP: i32 = -307; +pub const MIN_10_EXP: i32 = f64::MIN_10_EXP; /// Maximum possible power of 10 exponent. #[stable(feature = "rust1", since = "1.0.0")] -pub const MAX_10_EXP: i32 = 308; +pub const MAX_10_EXP: i32 = f64::MAX_10_EXP; /// Not a Number (NaN). #[stable(feature = "rust1", since = "1.0.0")] -pub const NAN: f64 = 0.0_f64 / 0.0_f64; +pub const NAN: f64 = f64::NAN; /// Infinity (∞). #[stable(feature = "rust1", since = "1.0.0")] -pub const INFINITY: f64 = 1.0_f64 / 0.0_f64; +pub const INFINITY: f64 = f64::INFINITY; /// Negative infinity (−∞). #[stable(feature = "rust1", since = "1.0.0")] -pub const NEG_INFINITY: f64 = -1.0_f64 / 0.0_f64; +pub const NEG_INFINITY: f64 = f64::NEG_INFINITY; /// Basic mathematical constants. #[stable(feature = "rust1", since = "1.0.0")] @@ -153,6 +153,59 @@ pub mod consts { #[lang = "f64"] #[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")] + pub const RADIX: u32 = 2; + + /// Number of significant digits in base 2. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const MANTISSA_DIGITS: u32 = 53; + /// Approximate number of significant digits in base 10. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const DIGITS: u32 = 15; + + /// [Machine epsilon] value for `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")] + pub const EPSILON: f64 = 2.2204460492503131e-16_f64; + + /// Smallest finite `f64` value. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const MIN: f64 = -1.7976931348623157e+308_f64; + /// Smallest positive normal `f64` value. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308_f64; + /// Largest finite `f64` value. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + 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")] + pub const MIN_EXP: i32 = -1021; + /// Maximum possible power of 2 exponent. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const MAX_EXP: i32 = 1024; + + /// Minimum possible normal power of 10 exponent. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const MIN_10_EXP: i32 = -307; + /// Maximum possible power of 10 exponent. + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const MAX_10_EXP: i32 = 308; + + /// Not a Number (NaN). + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const NAN: f64 = 0.0_f64 / 0.0_f64; + /// Infinity (∞). + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const INFINITY: f64 = 1.0_f64 / 0.0_f64; + /// Negative infinity (-∞). + #[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")] + pub const NEG_INFINITY: f64 = -1.0_f64 / 0.0_f64; + /// Returns `true` if this value is `NaN`. /// /// ``` From 9d257579fcaa44f69c8f7d5f668b05ae89e4507b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Fri, 17 Jan 2020 20:49:33 +0100 Subject: [PATCH 3/8] Fix some float operations to work together with the assoc consts --- src/libcore/num/dec2flt/rawfp.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libcore/num/dec2flt/rawfp.rs b/src/libcore/num/dec2flt/rawfp.rs index a127c6c3fa7ce..0ab15b23e5337 100644 --- a/src/libcore/num/dec2flt/rawfp.rs +++ b/src/libcore/num/dec2flt/rawfp.rs @@ -129,15 +129,15 @@ macro_rules! other_constants { ($type: ident) => { const EXPLICIT_SIG_BITS: u8 = Self::SIG_BITS - 1; const MAX_EXP: i16 = (1 << (Self::EXP_BITS - 1)) - 1; - const MIN_EXP: i16 = -Self::MAX_EXP + 1; - const MAX_EXP_INT: i16 = Self::MAX_EXP - (Self::SIG_BITS as i16 - 1); + const MIN_EXP: i16 = -::MAX_EXP + 1; + const MAX_EXP_INT: i16 = ::MAX_EXP - (Self::SIG_BITS as i16 - 1); const MAX_ENCODED_EXP: i16 = (1 << Self::EXP_BITS) - 1; - const MIN_EXP_INT: i16 = Self::MIN_EXP - (Self::SIG_BITS as i16 - 1); + const MIN_EXP_INT: i16 = ::MIN_EXP - (Self::SIG_BITS as i16 - 1); const MAX_SIG: u64 = (1 << Self::SIG_BITS) - 1; const MIN_SIG: u64 = 1 << (Self::SIG_BITS - 1); - const INFINITY: Self = $crate::$type::INFINITY; - const NAN: Self = $crate::$type::NAN; + const INFINITY: Self = $type::INFINITY; + const NAN: Self = $type::NAN; const ZERO: Self = 0.0; }; } From 6ce16cfa42dcb1acd2c823a1d45269132d372409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Fri, 17 Jan 2020 23:01:42 +0100 Subject: [PATCH 4/8] Remove no longer valid test --- src/test/ui/issues/issue-22933-3.rs | 4 ---- src/test/ui/issues/issue-22933-3.stderr | 14 -------------- 2 files changed, 18 deletions(-) delete mode 100644 src/test/ui/issues/issue-22933-3.rs delete mode 100644 src/test/ui/issues/issue-22933-3.stderr diff --git a/src/test/ui/issues/issue-22933-3.rs b/src/test/ui/issues/issue-22933-3.rs deleted file mode 100644 index fbcce4b834467..0000000000000 --- a/src/test/ui/issues/issue-22933-3.rs +++ /dev/null @@ -1,4 +0,0 @@ -const FOO: [u32; u8::MIN as usize] = []; -//~^ ERROR no associated item named `MIN` found - -fn main() {} diff --git a/src/test/ui/issues/issue-22933-3.stderr b/src/test/ui/issues/issue-22933-3.stderr deleted file mode 100644 index 72bca3b040839..0000000000000 --- a/src/test/ui/issues/issue-22933-3.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0599]: no associated item named `MIN` found for type `u8` in the current scope - --> $DIR/issue-22933-3.rs:1:22 - | -LL | const FOO: [u32; u8::MIN as usize] = []; - | ^^^ associated item not found in `u8` - | -help: you are looking for the module in `std`, not the primitive type - | -LL | const FOO: [u32; std::u8::MIN as usize] = []; - | ^^^^^^^^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0599`. From 9fcbaa4158948324f395ff2eb8061abdf6dbc21f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Sun, 19 Jan 2020 01:51:18 +0100 Subject: [PATCH 5/8] Fix broken show-const-contents test --- src/test/rustdoc/show-const-contents.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/rustdoc/show-const-contents.rs b/src/test/rustdoc/show-const-contents.rs index e84f6e52c75aa..064c026e6a078 100644 --- a/src/test/rustdoc/show-const-contents.rs +++ b/src/test/rustdoc/show-const-contents.rs @@ -47,9 +47,9 @@ pub struct MyTypeWithStr(&'static str); // @!has show_const_contents/constant.MY_TYPE_WITH_STR.html '; //' pub const MY_TYPE_WITH_STR: MyTypeWithStr = MyTypeWithStr("show this"); -// @has show_const_contents/constant.EPSILON.html '1.1920929e-7f32;' -// @!has show_const_contents/constant.EPSILON.html '; //' -pub use std::f32::EPSILON; +// @has show_const_contents/constant.PI.html '= 3.14159265358979323846264338327950288f32;' +// @has show_const_contents/constant.PI.html '; // 3.14159274f32' +pub use std::f32::consts::PI; // @has show_const_contents/constant.MAX.html '= i32::max_value(); // 2_147_483_647i32' pub use std::i32::MAX; From 4d9e90d2a5146e3f8639b53f29e210be94b30933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Sun, 19 Jan 2020 23:06:07 +0100 Subject: [PATCH 6/8] Unlock assoc_int_consts in core+std --- src/libcore/lib.rs | 1 + src/libstd/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index f77b4d7461e74..ce7ddffd82584 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -134,6 +134,7 @@ #![feature(const_type_id)] #![feature(const_caller_location)] #![cfg_attr(bootstrap, feature(slice_patterns))] +#![feature(assoc_int_consts)] #[prelude_import] #[allow(unused)] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index dc93ac90482fb..bc07c6b487b17 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -237,6 +237,7 @@ #![feature(arbitrary_self_types)] #![feature(array_error_internals)] #![feature(asm)] +#![feature(assoc_int_consts)] #![feature(associated_type_bounds)] #![feature(box_syntax)] #![feature(c_variadic)] From 002c7897a6c92397f6682bf7e9e86c9b4efd5c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Wed, 22 Jan 2020 23:37:03 +0100 Subject: [PATCH 7/8] Unlock assoc_int_consts in documentation examples using it --- src/libcore/num/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index e717d0e42bb00..7480e93421b54 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -252,6 +252,7 @@ macro_rules! int_impl { Basic usage: ``` +#![feature(assoc_int_consts)] ", $Feature, "assert_eq!(", stringify!($SelfT), "::MIN, ", stringify!($Min), ");", $EndFeature, " ```"), @@ -267,6 +268,7 @@ $EndFeature, " Basic usage: ``` +#![feature(assoc_int_consts)] ", $Feature, "assert_eq!(", stringify!($SelfT), "::MAX, ", stringify!($Max), ");", $EndFeature, " ```"), @@ -2361,6 +2363,7 @@ 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")] @@ -2375,6 +2378,7 @@ Basic usage: Basic usage: ``` +#![feature(assoc_int_consts)] ", $Feature, "assert_eq!(", stringify!($SelfT), "::MAX, ", stringify!($MaxV), ");", $EndFeature, " ```"), From 61fecfb82fe088af6d3a7832b72f298064398aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Thu, 23 Jan 2020 20:10:43 +0100 Subject: [PATCH 8/8] Add test accessing the module level int/float consts --- src/test/ui/use-module-level-int-consts.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/test/ui/use-module-level-int-consts.rs diff --git a/src/test/ui/use-module-level-int-consts.rs b/src/test/ui/use-module-level-int-consts.rs new file mode 100644 index 0000000000000..758fb414eadf2 --- /dev/null +++ b/src/test/ui/use-module-level-int-consts.rs @@ -0,0 +1,11 @@ +// run-pass + +// Make sure the module level constants are still there and accessible even after +// the corresponding associated constants have been added, and later stabilized. +use std::{u16, f32}; + +fn main() { + let _ = u16::MAX; + let _ = f32::EPSILON; + let _ = std::f64::MANTISSA_DIGITS; +}