From aca37b65f10e9aff3dfc04dcf273b6cd2112b052 Mon Sep 17 00:00:00 2001 From: Trevor Spiteri Date: Fri, 2 Oct 2020 19:30:16 +0200 Subject: [PATCH 1/2] stabilize const_int_pow Also stabilize constctlz for const ctlz_nonzero. The public methods stabilized const by this commit are: * `{i*,u*}::checked_pow` * `{i*,u*}::saturating_pow` * `{i*,u*}::wrapping_pow` * `{i*,u*}::overflowing_pow` * `{i*,u*}::pow` * `u*::next_power_of_two` * `u*::checked_next_power_of_two` * `u*::wrapping_next_power_of_two` (the method itself is still unstable) --- library/core/src/intrinsics.rs | 2 +- library/core/src/lib.rs | 2 -- library/core/src/num/int_macros.rs | 10 +++++----- library/core/src/num/uint_macros.rs | 18 +++++++++--------- src/test/ui/consts/const-int-pow-rpass.rs | 1 - 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 433f0129306bd..c5b4a0abdb537 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1486,7 +1486,7 @@ extern "rust-intrinsic" { /// let num_leading = unsafe { ctlz_nonzero(x) }; /// assert_eq!(num_leading, 3); /// ``` - #[rustc_const_unstable(feature = "constctlz", issue = "none")] + #[rustc_const_stable(feature = "constctlz", since = "1.49.0")] pub fn ctlz_nonzero(x: T) -> T; /// Returns the number of trailing unset bits (zeroes) in an integer type `T`. diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 0f91ff418e3ac..cb4c24c39677d 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -78,8 +78,6 @@ #![feature(const_overflowing_int_methods)] #![feature(const_int_unchecked_arith)] #![feature(const_mut_refs)] -#![feature(const_int_pow)] -#![feature(constctlz)] #![feature(const_cttz)] #![feature(const_panic)] #![feature(const_pin)] diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 289f14a360a34..ee309775bae11 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -791,7 +791,7 @@ $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -974,7 +974,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(3), ", stringify!($SelfT $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1340,7 +1340,7 @@ assert_eq!(3i8.wrapping_pow(6), -39);", $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1707,7 +1707,7 @@ assert_eq!(3i8.overflowing_pow(5), (-13, true));", $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1757,7 +1757,7 @@ assert_eq!(x.pow(5), 32);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index dbdc9c0fb5fcc..4e2691c0df07b 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -749,7 +749,7 @@ Basic usage: 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")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -865,7 +865,7 @@ assert_eq!(", stringify!($SelfT), "::MAX.saturating_pow(2), ", stringify!($SelfT $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1159,7 +1159,7 @@ Basic usage: assert_eq!(3u8.wrapping_pow(6), 217);", $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1484,7 +1484,7 @@ Basic usage: assert_eq!(3u8.overflowing_pow(6), (217, true));", $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1532,7 +1532,7 @@ Basic usage: ", $Feature, "assert_eq!(2", stringify!($SelfT), ".pow(5), 32);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1648,7 +1648,7 @@ assert!(!10", stringify!($SelfT), ".is_power_of_two());", $EndFeature, " // overflow cases it instead ends up returning the maximum value // of the type, and can return 0 for 0. #[inline] - #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] const fn one_less_than_next_power_of_two(self) -> Self { if self <= 1 { return 0; } @@ -1677,7 +1677,7 @@ Basic usage: assert_eq!(3", stringify!($SelfT), ".next_power_of_two(), 4);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] #[inline] #[rustc_inherit_overflow_checks] pub const fn next_power_of_two(self) -> Self { @@ -1703,7 +1703,7 @@ $EndFeature, " ```"), #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] pub const fn checked_next_power_of_two(self) -> Option { self.one_less_than_next_power_of_two().checked_add(1) } @@ -1728,7 +1728,7 @@ $EndFeature, " ```"), #[unstable(feature = "wrapping_next_power_of_two", issue = "32463", reason = "needs decision on wrapping behaviour")] - #[rustc_const_unstable(feature = "const_int_pow", issue = "53718")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] pub const fn wrapping_next_power_of_two(self) -> Self { self.one_less_than_next_power_of_two().wrapping_add(1) } diff --git a/src/test/ui/consts/const-int-pow-rpass.rs b/src/test/ui/consts/const-int-pow-rpass.rs index 4f936236dbb20..30bcb78bcf270 100644 --- a/src/test/ui/consts/const-int-pow-rpass.rs +++ b/src/test/ui/consts/const-int-pow-rpass.rs @@ -1,6 +1,5 @@ // run-pass -#![feature(const_int_pow)] #![feature(wrapping_next_power_of_two)] const IS_POWER_OF_TWO_A: bool = 0u32.is_power_of_two(); From a6bcf7a2b6c6bc9557791d3075bb376196945727 Mon Sep 17 00:00:00 2001 From: Trevor Spiteri Date: Mon, 23 Nov 2020 02:04:37 +0100 Subject: [PATCH 2/2] const_int_pow will be stabilized in 1.50.0, not in 1.49.0 Same for constctlz. --- library/core/src/intrinsics.rs | 2 +- library/core/src/num/int_macros.rs | 10 +++++----- library/core/src/num/uint_macros.rs | 18 +++++++++--------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index c5b4a0abdb537..5a5aa76a07627 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1486,7 +1486,7 @@ extern "rust-intrinsic" { /// let num_leading = unsafe { ctlz_nonzero(x) }; /// assert_eq!(num_leading, 3); /// ``` - #[rustc_const_stable(feature = "constctlz", since = "1.49.0")] + #[rustc_const_stable(feature = "constctlz", since = "1.50.0")] pub fn ctlz_nonzero(x: T) -> T; /// Returns the number of trailing unset bits (zeroes) in an integer type `T`. diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index ee309775bae11..33eefe5d26580 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -791,7 +791,7 @@ $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -974,7 +974,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(3), ", stringify!($SelfT $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1340,7 +1340,7 @@ assert_eq!(3i8.wrapping_pow(6), -39);", $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1707,7 +1707,7 @@ assert_eq!(3i8.overflowing_pow(5), (-13, true));", $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1757,7 +1757,7 @@ assert_eq!(x.pow(5), 32);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 4e2691c0df07b..390c1b7e9e871 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -749,7 +749,7 @@ Basic usage: assert_eq!(", stringify!($SelfT), "::MAX.checked_pow(2), None);", $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -865,7 +865,7 @@ assert_eq!(", stringify!($SelfT), "::MAX.saturating_pow(2), ", stringify!($SelfT $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1159,7 +1159,7 @@ Basic usage: assert_eq!(3u8.wrapping_pow(6), 217);", $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1484,7 +1484,7 @@ Basic usage: assert_eq!(3u8.overflowing_pow(6), (217, true));", $EndFeature, " ```"), #[stable(feature = "no_panic_pow", since = "1.34.0")] - #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1532,7 +1532,7 @@ Basic usage: ", $Feature, "assert_eq!(2", stringify!($SelfT), ".pow(5), 32);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1648,7 +1648,7 @@ assert!(!10", stringify!($SelfT), ".is_power_of_two());", $EndFeature, " // overflow cases it instead ends up returning the maximum value // of the type, and can return 0 for 0. #[inline] - #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] const fn one_less_than_next_power_of_two(self) -> Self { if self <= 1 { return 0; } @@ -1677,7 +1677,7 @@ Basic usage: assert_eq!(3", stringify!($SelfT), ".next_power_of_two(), 4);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] #[inline] #[rustc_inherit_overflow_checks] pub const fn next_power_of_two(self) -> Self { @@ -1703,7 +1703,7 @@ $EndFeature, " ```"), #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] pub const fn checked_next_power_of_two(self) -> Option { self.one_less_than_next_power_of_two().checked_add(1) } @@ -1728,7 +1728,7 @@ $EndFeature, " ```"), #[unstable(feature = "wrapping_next_power_of_two", issue = "32463", reason = "needs decision on wrapping behaviour")] - #[rustc_const_stable(feature = "const_int_pow", since = "1.49.0")] + #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] pub const fn wrapping_next_power_of_two(self) -> Self { self.one_less_than_next_power_of_two().wrapping_add(1) }