Make unchecked_{add,sub,mul} inherent methods unstably const

This commit is contained in:
ltdk 2021-05-08 20:18:44 -04:00
parent 777bb2f612
commit 380bbe8d47
3 changed files with 19 additions and 12 deletions

View File

@ -77,6 +77,7 @@
#![feature(const_float_classify)] #![feature(const_float_classify)]
#![feature(const_float_bits_conv)] #![feature(const_float_bits_conv)]
#![feature(const_int_unchecked_arith)] #![feature(const_int_unchecked_arith)]
#![feature(const_inherent_unchecked_arith)]
#![feature(const_mut_refs)] #![feature(const_mut_refs)]
#![feature(const_refs_to_cell)] #![feature(const_refs_to_cell)]
#![feature(const_panic)] #![feature(const_panic)]

View File

@ -412,12 +412,13 @@ macro_rules! int_impl {
#[unstable( #[unstable(
feature = "unchecked_math", feature = "unchecked_math",
reason = "niche optimization path", reason = "niche optimization path",
issue = "none", issue = "85122",
)] )]
#[must_use = "this returns the result of the operation, \ #[must_use = "this returns the result of the operation, \
without modifying the original"] without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[inline(always)] #[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 // SAFETY: the caller must uphold the safety contract for
// `unchecked_add`. // `unchecked_add`.
unsafe { intrinsics::unchecked_add(self, rhs) } unsafe { intrinsics::unchecked_add(self, rhs) }
@ -450,12 +451,13 @@ macro_rules! int_impl {
#[unstable( #[unstable(
feature = "unchecked_math", feature = "unchecked_math",
reason = "niche optimization path", reason = "niche optimization path",
issue = "none", issue = "85122",
)] )]
#[must_use = "this returns the result of the operation, \ #[must_use = "this returns the result of the operation, \
without modifying the original"] without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[inline(always)] #[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 // SAFETY: the caller must uphold the safety contract for
// `unchecked_sub`. // `unchecked_sub`.
unsafe { intrinsics::unchecked_sub(self, rhs) } unsafe { intrinsics::unchecked_sub(self, rhs) }
@ -488,12 +490,13 @@ macro_rules! int_impl {
#[unstable( #[unstable(
feature = "unchecked_math", feature = "unchecked_math",
reason = "niche optimization path", reason = "niche optimization path",
issue = "none", issue = "85122",
)] )]
#[must_use = "this returns the result of the operation, \ #[must_use = "this returns the result of the operation, \
without modifying the original"] without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[inline(always)] #[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 // SAFETY: the caller must uphold the safety contract for
// `unchecked_mul`. // `unchecked_mul`.
unsafe { intrinsics::unchecked_mul(self, rhs) } unsafe { intrinsics::unchecked_mul(self, rhs) }

View File

@ -422,12 +422,13 @@ macro_rules! uint_impl {
#[unstable( #[unstable(
feature = "unchecked_math", feature = "unchecked_math",
reason = "niche optimization path", reason = "niche optimization path",
issue = "none", issue = "85122",
)] )]
#[must_use = "this returns the result of the operation, \ #[must_use = "this returns the result of the operation, \
without modifying the original"] without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[inline(always)] #[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 // SAFETY: the caller must uphold the safety contract for
// `unchecked_add`. // `unchecked_add`.
unsafe { intrinsics::unchecked_add(self, rhs) } unsafe { intrinsics::unchecked_add(self, rhs) }
@ -460,12 +461,13 @@ macro_rules! uint_impl {
#[unstable( #[unstable(
feature = "unchecked_math", feature = "unchecked_math",
reason = "niche optimization path", reason = "niche optimization path",
issue = "none", issue = "85122",
)] )]
#[must_use = "this returns the result of the operation, \ #[must_use = "this returns the result of the operation, \
without modifying the original"] without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[inline(always)] #[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 // SAFETY: the caller must uphold the safety contract for
// `unchecked_sub`. // `unchecked_sub`.
unsafe { intrinsics::unchecked_sub(self, rhs) } unsafe { intrinsics::unchecked_sub(self, rhs) }
@ -498,12 +500,13 @@ macro_rules! uint_impl {
#[unstable( #[unstable(
feature = "unchecked_math", feature = "unchecked_math",
reason = "niche optimization path", reason = "niche optimization path",
issue = "none", issue = "85122",
)] )]
#[must_use = "this returns the result of the operation, \ #[must_use = "this returns the result of the operation, \
without modifying the original"] without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[inline(always)] #[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 // SAFETY: the caller must uphold the safety contract for
// `unchecked_mul`. // `unchecked_mul`.
unsafe { intrinsics::unchecked_mul(self, rhs) } unsafe { intrinsics::unchecked_mul(self, rhs) }