From 265e03332bfe66ec3f376f81b09810e7a5c780a4 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Wed, 13 Jan 2021 04:57:28 -0500 Subject: [PATCH 1/2] Stabilize remaining integer methods as `const fn` This includes the following functions: - i*::checked_div - i*::checked_div_euclid - i*::checked_rem - i*::checked_rem_euclid - i*::div_euclid - i*::overflowing_div - i*::overflowing_div_euclid - i*::overflowing_rem - i*::overflowing_rem_euclid - i*::rem_euclid - i*::wrapping_div - i*::wrapping_div_euclid - i*::wrapping_rem - i*::wrapping_rem_euclid - u*::checked_div - u*::checked_div_euclid - u*::checked_rem - u*::checked_rem_euclid - u*::div_euclid - u*::overflowing_div - u*::overflowing_div_euclid - u*::overflowing_rem - u*::overflowing_rem_euclid - u*::rem_euclid - u*::wrapping_div - u*::wrapping_div_euclid - u*::wrapping_rem - u*::wrapping_rem_euclid --- library/core/src/lib.rs | 3 --- library/core/src/num/int_macros.rs | 30 ++++++++++++---------- library/core/src/num/uint_macros.rs | 30 ++++++++++++---------- src/test/ui/consts/const-int-arithmetic.rs | 5 ---- 4 files changed, 32 insertions(+), 36 deletions(-) diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index df8d9ff371fe4..157d26725c5ed 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -73,11 +73,8 @@ #![feature(const_discriminant)] #![feature(const_cell_into_inner)] #![feature(const_intrinsic_copy)] -#![feature(const_checked_int_methods)] -#![feature(const_euclidean_int_methods)] #![feature(const_float_classify)] #![feature(const_float_bits_conv)] -#![feature(const_overflowing_int_methods)] #![feature(const_int_unchecked_arith)] #![feature(const_mut_refs)] #![feature(const_cttz)] diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 162ed7d1b8dfe..810ca9b357e74 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -513,7 +513,8 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!((1", stringify!($SelfT), ").checked_div(0), None);")] /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.51.0")] + #[rustc_allow_const_fn_unstable(const_int_unchecked_arith)] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -539,7 +540,7 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!((1", stringify!($SelfT), ").checked_div_euclid(0), None);")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -565,7 +566,8 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_rem(-1), None);")] /// ``` #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.51.0")] + #[rustc_allow_const_fn_unstable(const_int_unchecked_arith)] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -591,7 +593,7 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_rem_euclid(-1), None);")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -949,7 +951,7 @@ macro_rules! int_impl { /// assert_eq!((-128i8).wrapping_div(-1), -128); /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] - #[rustc_const_unstable(feature = "const_wrapping_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_wrapping_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -977,7 +979,7 @@ macro_rules! int_impl { /// assert_eq!((-128i8).wrapping_div_euclid(-1), -128); /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1005,7 +1007,7 @@ macro_rules! int_impl { /// assert_eq!((-128i8).wrapping_rem(-1), 0); /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] - #[rustc_const_unstable(feature = "const_wrapping_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_wrapping_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1032,7 +1034,7 @@ macro_rules! int_impl { /// assert_eq!((-128i8).wrapping_rem_euclid(-1), 0); /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1299,7 +1301,7 @@ macro_rules! int_impl { /// ``` #[inline] #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_unstable(feature = "const_overflowing_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) { @@ -1329,7 +1331,7 @@ macro_rules! int_impl { /// ``` #[inline] #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) { @@ -1360,7 +1362,7 @@ macro_rules! int_impl { /// ``` #[inline] #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_unstable(feature = "const_overflowing_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) { @@ -1390,7 +1392,7 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_rem_euclid(-1), (0, true));")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1615,7 +1617,7 @@ macro_rules! int_impl { /// assert_eq!((-a).div_euclid(-b), 2); // -7 >= -4 * 2 /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1653,7 +1655,7 @@ macro_rules! int_impl { /// assert_eq!((-a).rem_euclid(-b), 1); /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.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 8f141a3ff9e97..89b16342d9517 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -522,7 +522,8 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_div(0), None);")] /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.51.0")] + #[rustc_allow_const_fn_unstable(const_int_unchecked_arith)] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -548,7 +549,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_div_euclid(0), None);")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -573,7 +574,8 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem(0), None);")] /// ``` #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.51.0")] + #[rustc_allow_const_fn_unstable(const_int_unchecked_arith)] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -599,7 +601,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(0), None);")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -876,7 +878,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_div(10), 10);")] /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] - #[rustc_const_unstable(feature = "const_wrapping_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_wrapping_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -901,7 +903,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_div_euclid(10), 10);")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -924,7 +926,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_rem(10), 0);")] /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] - #[rustc_const_unstable(feature = "const_wrapping_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_wrapping_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -950,7 +952,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_rem_euclid(10), 0);")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1185,7 +1187,7 @@ macro_rules! uint_impl { /// ``` #[inline] #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_unstable(feature = "const_overflowing_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) { @@ -1215,7 +1217,7 @@ macro_rules! uint_impl { /// ``` #[inline] #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) { @@ -1242,7 +1244,7 @@ macro_rules! uint_impl { /// ``` #[inline] #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_unstable(feature = "const_overflowing_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) { @@ -1272,7 +1274,7 @@ macro_rules! uint_impl { /// ``` #[inline] #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) { @@ -1456,7 +1458,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(7", stringify!($SelfT), ".div_euclid(4), 1); // or any other integer type")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1484,7 +1486,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(7", stringify!($SelfT), ".rem_euclid(4), 3); // or any other integer type")] /// ``` #[stable(feature = "euclidean_division", since = "1.38.0")] - #[rustc_const_unstable(feature = "const_euclidean_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.51.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/src/test/ui/consts/const-int-arithmetic.rs b/src/test/ui/consts/const-int-arithmetic.rs index e0d722ede94e3..b9096648f9235 100644 --- a/src/test/ui/consts/const-int-arithmetic.rs +++ b/src/test/ui/consts/const-int-arithmetic.rs @@ -1,10 +1,5 @@ // run-pass -#![feature(const_checked_int_methods)] -#![feature(const_euclidean_int_methods)] -#![feature(const_overflowing_int_methods)] -#![feature(const_wrapping_int_methods)] - macro_rules! suite { ($( $fn:ident -> $ty:ty { $( $label:ident : $expr:expr, $result:expr; )* } From f55029ab04e0d416db24af9b537be26e808f6f59 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Thu, 14 Jan 2021 18:55:37 -0500 Subject: [PATCH 2/2] Stabilize intrinsics as const --- library/core/src/intrinsics.rs | 4 ++-- library/core/src/num/int_macros.rs | 2 -- library/core/src/num/uint_macros.rs | 2 -- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 0130586b43042..653fbcabfe56d 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1593,7 +1593,7 @@ extern "rust-intrinsic" { /// Safe wrappers for this intrinsic are available on the integer /// primitives via the `checked_div` method. For example, /// [`u32::checked_div`] - #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")] + #[rustc_const_stable(feature = "const_int_unchecked_arith", since = "1.51.0")] pub fn unchecked_div(x: T, y: T) -> T; /// Returns the remainder of an unchecked division, resulting in /// undefined behavior when `y == 0` or `x == T::MIN && y == -1` @@ -1601,7 +1601,7 @@ extern "rust-intrinsic" { /// Safe wrappers for this intrinsic are available on the integer /// primitives via the `checked_rem` method. For example, /// [`u32::checked_rem`] - #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")] + #[rustc_const_stable(feature = "const_int_unchecked_arith", since = "1.51.0")] pub fn unchecked_rem(x: T, y: T) -> T; /// Performs an unchecked left shift, resulting in undefined behavior when diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 810ca9b357e74..2e2e1b0f2ec86 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -514,7 +514,6 @@ macro_rules! int_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.51.0")] - #[rustc_allow_const_fn_unstable(const_int_unchecked_arith)] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -567,7 +566,6 @@ macro_rules! int_impl { /// ``` #[stable(feature = "wrapping", since = "1.7.0")] #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.51.0")] - #[rustc_allow_const_fn_unstable(const_int_unchecked_arith)] #[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 89b16342d9517..3f235c20123ee 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -523,7 +523,6 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.51.0")] - #[rustc_allow_const_fn_unstable(const_int_unchecked_arith)] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -575,7 +574,6 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "wrapping", since = "1.7.0")] #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.51.0")] - #[rustc_allow_const_fn_unstable(const_int_unchecked_arith)] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline]