Added const versions of common numeric operations

# Conflicts:
#	library/core/src/lib.rs
This commit is contained in:
AlexApps99
2021-10-22 10:03:18 +13:00
parent 547a6ffee0
commit 23d033e177
6 changed files with 232 additions and 106 deletions

View File

@@ -54,14 +54,15 @@ pub trait Not {
macro_rules! not_impl {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
impl Not for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const Not for $t {
type Output = $t;
#[inline]
fn not(self) -> $t { !self }
}
forward_ref_unop! { impl Not, not for $t }
forward_ref_unop! { impl const Not, not for $t }
)*)
}
@@ -154,14 +155,15 @@ pub trait BitAnd<Rhs = Self> {
macro_rules! bitand_impl {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
impl BitAnd for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const BitAnd for $t {
type Output = $t;
#[inline]
fn bitand(self, rhs: $t) -> $t { self & rhs }
}
forward_ref_binop! { impl BitAnd, bitand for $t, $t }
forward_ref_binop! { impl const BitAnd, bitand for $t, $t }
)*)
}
@@ -254,14 +256,15 @@ pub trait BitOr<Rhs = Self> {
macro_rules! bitor_impl {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
impl BitOr for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const BitOr for $t {
type Output = $t;
#[inline]
fn bitor(self, rhs: $t) -> $t { self | rhs }
}
forward_ref_binop! { impl BitOr, bitor for $t, $t }
forward_ref_binop! { impl const BitOr, bitor for $t, $t }
)*)
}
@@ -354,14 +357,15 @@ pub trait BitXor<Rhs = Self> {
macro_rules! bitxor_impl {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
impl BitXor for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const BitXor for $t {
type Output = $t;
#[inline]
fn bitxor(self, other: $t) -> $t { self ^ other }
}
forward_ref_binop! { impl BitXor, bitxor for $t, $t }
forward_ref_binop! { impl const BitXor, bitxor for $t, $t }
)*)
}
@@ -451,7 +455,8 @@ pub trait Shl<Rhs = Self> {
macro_rules! shl_impl {
($t:ty, $f:ty) => {
#[stable(feature = "rust1", since = "1.0.0")]
impl Shl<$f> for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const Shl<$f> for $t {
type Output = $t;
#[inline]
@@ -461,7 +466,7 @@ macro_rules! shl_impl {
}
}
forward_ref_binop! { impl Shl, shl for $t, $f }
forward_ref_binop! { impl const Shl, shl for $t, $f }
};
}
@@ -569,7 +574,8 @@ pub trait Shr<Rhs = Self> {
macro_rules! shr_impl {
($t:ty, $f:ty) => {
#[stable(feature = "rust1", since = "1.0.0")]
impl Shr<$f> for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const Shr<$f> for $t {
type Output = $t;
#[inline]
@@ -579,7 +585,7 @@ macro_rules! shr_impl {
}
}
forward_ref_binop! { impl Shr, shr for $t, $f }
forward_ref_binop! { impl const Shr, shr for $t, $f }
};
}
@@ -704,12 +710,13 @@ pub trait BitAndAssign<Rhs = Self> {
macro_rules! bitand_assign_impl {
($($t:ty)+) => ($(
#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl BitAndAssign for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const BitAndAssign for $t {
#[inline]
fn bitand_assign(&mut self, other: $t) { *self &= other }
}
forward_ref_op_assign! { impl BitAndAssign, bitand_assign for $t, $t }
forward_ref_op_assign! { impl const BitAndAssign, bitand_assign for $t, $t }
)+)
}
@@ -775,12 +782,13 @@ pub trait BitOrAssign<Rhs = Self> {
macro_rules! bitor_assign_impl {
($($t:ty)+) => ($(
#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl BitOrAssign for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const BitOrAssign for $t {
#[inline]
fn bitor_assign(&mut self, other: $t) { *self |= other }
}
forward_ref_op_assign! { impl BitOrAssign, bitor_assign for $t, $t }
forward_ref_op_assign! { impl const BitOrAssign, bitor_assign for $t, $t }
)+)
}
@@ -846,12 +854,13 @@ pub trait BitXorAssign<Rhs = Self> {
macro_rules! bitxor_assign_impl {
($($t:ty)+) => ($(
#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl BitXorAssign for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const BitXorAssign for $t {
#[inline]
fn bitxor_assign(&mut self, other: $t) { *self ^= other }
}
forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for $t, $t }
forward_ref_op_assign! { impl const BitXorAssign, bitxor_assign for $t, $t }
)+)
}
@@ -907,7 +916,8 @@ pub trait ShlAssign<Rhs = Self> {
macro_rules! shl_assign_impl {
($t:ty, $f:ty) => {
#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl ShlAssign<$f> for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const ShlAssign<$f> for $t {
#[inline]
#[rustc_inherit_overflow_checks]
fn shl_assign(&mut self, other: $f) {
@@ -915,7 +925,7 @@ macro_rules! shl_assign_impl {
}
}
forward_ref_op_assign! { impl ShlAssign, shl_assign for $t, $f }
forward_ref_op_assign! { impl const ShlAssign, shl_assign for $t, $f }
};
}
@@ -989,7 +999,8 @@ pub trait ShrAssign<Rhs = Self> {
macro_rules! shr_assign_impl {
($t:ty, $f:ty) => {
#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl ShrAssign<$f> for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const ShrAssign<$f> for $t {
#[inline]
#[rustc_inherit_overflow_checks]
fn shr_assign(&mut self, other: $f) {
@@ -997,7 +1008,7 @@ macro_rules! shr_assign_impl {
}
}
forward_ref_op_assign! { impl ShrAssign, shr_assign for $t, $f }
forward_ref_op_assign! { impl const ShrAssign, shr_assign for $t, $f }
};
}