Skip to content

Commit 297050f

Browse files
committed
Trivially constify remaining operators
1 parent 600a02c commit 297050f

File tree

3 files changed

+106
-35
lines changed

3 files changed

+106
-35
lines changed

library/core/src/ops/arith.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,9 @@ rem_impl_float! { f16 f32 f64 f128 }
685685
/// ```
686686
#[lang = "neg"]
687687
#[stable(feature = "rust1", since = "1.0.0")]
688+
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
688689
#[doc(alias = "-")]
690+
#[const_trait]
689691
pub trait Neg {
690692
/// The resulting type after applying the `-` operator.
691693
#[stable(feature = "rust1", since = "1.0.0")]
@@ -708,7 +710,8 @@ pub trait Neg {
708710
macro_rules! neg_impl {
709711
($($t:ty)*) => ($(
710712
#[stable(feature = "rust1", since = "1.0.0")]
711-
impl Neg for $t {
713+
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
714+
impl const Neg for $t {
712715
type Output = $t;
713716

714717
#[inline]
@@ -754,12 +757,14 @@ neg_impl! { isize i8 i16 i32 i64 i128 f16 f32 f64 f128 }
754757
/// ```
755758
#[lang = "add_assign"]
756759
#[stable(feature = "op_assign_traits", since = "1.8.0")]
760+
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
757761
#[diagnostic::on_unimplemented(
758762
message = "cannot add-assign `{Rhs}` to `{Self}`",
759763
label = "no implementation for `{Self} += {Rhs}`"
760764
)]
761765
#[doc(alias = "+")]
762766
#[doc(alias = "+=")]
767+
#[const_trait]
763768
pub trait AddAssign<Rhs = Self> {
764769
/// Performs the `+=` operation.
765770
///
@@ -777,7 +782,8 @@ pub trait AddAssign<Rhs = Self> {
777782
macro_rules! add_assign_impl {
778783
($($t:ty)+) => ($(
779784
#[stable(feature = "op_assign_traits", since = "1.8.0")]
780-
impl AddAssign for $t {
785+
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
786+
impl const AddAssign for $t {
781787
#[inline]
782788
#[track_caller]
783789
#[rustc_inherit_overflow_checks]
@@ -822,12 +828,14 @@ add_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f
822828
/// ```
823829
#[lang = "sub_assign"]
824830
#[stable(feature = "op_assign_traits", since = "1.8.0")]
831+
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
825832
#[diagnostic::on_unimplemented(
826833
message = "cannot subtract-assign `{Rhs}` from `{Self}`",
827834
label = "no implementation for `{Self} -= {Rhs}`"
828835
)]
829836
#[doc(alias = "-")]
830837
#[doc(alias = "-=")]
838+
#[const_trait]
831839
pub trait SubAssign<Rhs = Self> {
832840
/// Performs the `-=` operation.
833841
///
@@ -845,7 +853,8 @@ pub trait SubAssign<Rhs = Self> {
845853
macro_rules! sub_assign_impl {
846854
($($t:ty)+) => ($(
847855
#[stable(feature = "op_assign_traits", since = "1.8.0")]
848-
impl SubAssign for $t {
856+
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
857+
impl const SubAssign for $t {
849858
#[inline]
850859
#[track_caller]
851860
#[rustc_inherit_overflow_checks]
@@ -881,12 +890,14 @@ sub_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f
881890
/// ```
882891
#[lang = "mul_assign"]
883892
#[stable(feature = "op_assign_traits", since = "1.8.0")]
893+
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
884894
#[diagnostic::on_unimplemented(
885895
message = "cannot multiply-assign `{Self}` by `{Rhs}`",
886896
label = "no implementation for `{Self} *= {Rhs}`"
887897
)]
888898
#[doc(alias = "*")]
889899
#[doc(alias = "*=")]
900+
#[const_trait]
890901
pub trait MulAssign<Rhs = Self> {
891902
/// Performs the `*=` operation.
892903
///
@@ -904,7 +915,8 @@ pub trait MulAssign<Rhs = Self> {
904915
macro_rules! mul_assign_impl {
905916
($($t:ty)+) => ($(
906917
#[stable(feature = "op_assign_traits", since = "1.8.0")]
907-
impl MulAssign for $t {
918+
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
919+
impl const MulAssign for $t {
908920
#[inline]
909921
#[track_caller]
910922
#[rustc_inherit_overflow_checks]
@@ -940,12 +952,14 @@ mul_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f
940952
/// ```
941953
#[lang = "div_assign"]
942954
#[stable(feature = "op_assign_traits", since = "1.8.0")]
955+
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
943956
#[diagnostic::on_unimplemented(
944957
message = "cannot divide-assign `{Self}` by `{Rhs}`",
945958
label = "no implementation for `{Self} /= {Rhs}`"
946959
)]
947960
#[doc(alias = "/")]
948961
#[doc(alias = "/=")]
962+
#[const_trait]
949963
pub trait DivAssign<Rhs = Self> {
950964
/// Performs the `/=` operation.
951965
///
@@ -963,7 +977,8 @@ pub trait DivAssign<Rhs = Self> {
963977
macro_rules! div_assign_impl {
964978
($($t:ty)+) => ($(
965979
#[stable(feature = "op_assign_traits", since = "1.8.0")]
966-
impl DivAssign for $t {
980+
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
981+
impl const DivAssign for $t {
967982
#[inline]
968983
#[track_caller]
969984
fn div_assign(&mut self, other: $t) { *self /= other }
@@ -1002,12 +1017,14 @@ div_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f
10021017
/// ```
10031018
#[lang = "rem_assign"]
10041019
#[stable(feature = "op_assign_traits", since = "1.8.0")]
1020+
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
10051021
#[diagnostic::on_unimplemented(
10061022
message = "cannot calculate and assign the remainder of `{Self}` divided by `{Rhs}`",
10071023
label = "no implementation for `{Self} %= {Rhs}`"
10081024
)]
10091025
#[doc(alias = "%")]
10101026
#[doc(alias = "%=")]
1027+
#[const_trait]
10111028
pub trait RemAssign<Rhs = Self> {
10121029
/// Performs the `%=` operation.
10131030
///
@@ -1025,7 +1042,8 @@ pub trait RemAssign<Rhs = Self> {
10251042
macro_rules! rem_assign_impl {
10261043
($($t:ty)+) => ($(
10271044
#[stable(feature = "op_assign_traits", since = "1.8.0")]
1028-
impl RemAssign for $t {
1045+
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
1046+
impl const RemAssign for $t {
10291047
#[inline]
10301048
#[track_caller]
10311049
fn rem_assign(&mut self, other: $t) { *self %= other }

0 commit comments

Comments
 (0)