diff options
| author | ltdk <usr@ltdk.xyz> | 2021-05-08 20:18:44 -0400 |
|---|---|---|
| committer | ltdk <usr@ltdk.xyz> | 2021-05-09 16:29:40 -0400 |
| commit | 380bbe8d478e2252b60b79b82f285b9464227f5c (patch) | |
| tree | 6c3f40aa51e93bbe1e39d0736781b99815db7699 | |
| parent | 777bb2f6129e71a88ba030251eb370ef12fe28af (diff) | |
| download | rust-380bbe8d478e2252b60b79b82f285b9464227f5c.tar.gz rust-380bbe8d478e2252b60b79b82f285b9464227f5c.zip | |
Make unchecked_{add,sub,mul} inherent methods unstably const
| -rw-r--r-- | library/core/src/lib.rs | 1 | ||||
| -rw-r--r-- | library/core/src/num/int_macros.rs | 15 | ||||
| -rw-r--r-- | library/core/src/num/uint_macros.rs | 15 |
3 files changed, 19 insertions, 12 deletions
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 0e2c140c367..71008381475 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -77,6 +77,7 @@ #![feature(const_float_classify)] #![feature(const_float_bits_conv)] #![feature(const_int_unchecked_arith)] +#![feature(const_inherent_unchecked_arith)] #![feature(const_mut_refs)] #![feature(const_refs_to_cell)] #![feature(const_panic)] diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 4b341132e31..47b2b30563c 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -412,12 +412,13 @@ macro_rules! int_impl { #[unstable( feature = "unchecked_math", reason = "niche optimization path", - issue = "none", + issue = "85122", )] #[must_use = "this returns the result of the operation, \ without modifying the original"] + #[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")] #[inline(always)] - pub unsafe fn unchecked_add(self, rhs: Self) -> Self { + pub const unsafe fn unchecked_add(self, rhs: Self) -> Self { // SAFETY: the caller must uphold the safety contract for // `unchecked_add`. unsafe { intrinsics::unchecked_add(self, rhs) } @@ -450,12 +451,13 @@ macro_rules! int_impl { #[unstable( feature = "unchecked_math", reason = "niche optimization path", - issue = "none", + issue = "85122", )] #[must_use = "this returns the result of the operation, \ without modifying the original"] + #[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")] #[inline(always)] - pub unsafe fn unchecked_sub(self, rhs: Self) -> Self { + pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self { // SAFETY: the caller must uphold the safety contract for // `unchecked_sub`. unsafe { intrinsics::unchecked_sub(self, rhs) } @@ -488,12 +490,13 @@ macro_rules! int_impl { #[unstable( feature = "unchecked_math", reason = "niche optimization path", - issue = "none", + issue = "85122", )] #[must_use = "this returns the result of the operation, \ without modifying the original"] + #[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")] #[inline(always)] - pub unsafe fn unchecked_mul(self, rhs: Self) -> Self { + pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self { // SAFETY: the caller must uphold the safety contract for // `unchecked_mul`. unsafe { intrinsics::unchecked_mul(self, rhs) } diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 08d9161eff1..f9fd28b6a8c 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -422,12 +422,13 @@ macro_rules! uint_impl { #[unstable( feature = "unchecked_math", reason = "niche optimization path", - issue = "none", + issue = "85122", )] #[must_use = "this returns the result of the operation, \ without modifying the original"] + #[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")] #[inline(always)] - pub unsafe fn unchecked_add(self, rhs: Self) -> Self { + pub const unsafe fn unchecked_add(self, rhs: Self) -> Self { // SAFETY: the caller must uphold the safety contract for // `unchecked_add`. unsafe { intrinsics::unchecked_add(self, rhs) } @@ -460,12 +461,13 @@ macro_rules! uint_impl { #[unstable( feature = "unchecked_math", reason = "niche optimization path", - issue = "none", + issue = "85122", )] #[must_use = "this returns the result of the operation, \ without modifying the original"] + #[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")] #[inline(always)] - pub unsafe fn unchecked_sub(self, rhs: Self) -> Self { + pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self { // SAFETY: the caller must uphold the safety contract for // `unchecked_sub`. unsafe { intrinsics::unchecked_sub(self, rhs) } @@ -498,12 +500,13 @@ macro_rules! uint_impl { #[unstable( feature = "unchecked_math", reason = "niche optimization path", - issue = "none", + issue = "85122", )] #[must_use = "this returns the result of the operation, \ without modifying the original"] + #[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")] #[inline(always)] - pub unsafe fn unchecked_mul(self, rhs: Self) -> Self { + pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self { // SAFETY: the caller must uphold the safety contract for // `unchecked_mul`. unsafe { intrinsics::unchecked_mul(self, rhs) } |
