1
Fork 0

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_bits_conv)]
#![feature(const_int_unchecked_arith)]
#![feature(const_inherent_unchecked_arith)]
#![feature(const_mut_refs)]
#![feature(const_refs_to_cell)]
#![feature(const_panic)]

View file

@ -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) }

View file

@ -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) }