Skip to content

Commit ec453f8

Browse files
committed
Rename const_ops to const_arith_ops, add to remaining arith traits
1 parent 500a041 commit ec453f8

File tree

8 files changed

+63
-37
lines changed

8 files changed

+63
-37
lines changed

library/core/src/ops/arith.rs

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
/// ```
6666
#[lang = "add"]
6767
#[stable(feature = "rust1", since = "1.0.0")]
68-
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
68+
#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")]
6969
#[rustc_on_unimplemented(
7070
on(all(Self = "{integer}", Rhs = "{float}"), message = "cannot add a float to an integer",),
7171
on(all(Self = "{float}", Rhs = "{integer}"), message = "cannot add an integer to a float",),
@@ -96,7 +96,7 @@ pub trait Add<Rhs = Self> {
9696
macro_rules! add_impl {
9797
($($t:ty)*) => ($(
9898
#[stable(feature = "rust1", since = "1.0.0")]
99-
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
99+
#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")]
100100
impl const Add for $t {
101101
type Output = $t;
102102

@@ -180,7 +180,7 @@ add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128
180180
/// ```
181181
#[lang = "sub"]
182182
#[stable(feature = "rust1", since = "1.0.0")]
183-
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
183+
#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")]
184184
#[rustc_on_unimplemented(
185185
message = "cannot subtract `{Rhs}` from `{Self}`",
186186
label = "no implementation for `{Self} - {Rhs}`",
@@ -209,7 +209,7 @@ pub trait Sub<Rhs = Self> {
209209
macro_rules! sub_impl {
210210
($($t:ty)*) => ($(
211211
#[stable(feature = "rust1", since = "1.0.0")]
212-
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
212+
#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")]
213213
impl const Sub for $t {
214214
type Output = $t;
215215

@@ -315,7 +315,7 @@ sub_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128
315315
/// ```
316316
#[lang = "mul"]
317317
#[stable(feature = "rust1", since = "1.0.0")]
318-
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
318+
#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")]
319319
#[diagnostic::on_unimplemented(
320320
message = "cannot multiply `{Self}` by `{Rhs}`",
321321
label = "no implementation for `{Self} * {Rhs}`"
@@ -343,7 +343,7 @@ pub trait Mul<Rhs = Self> {
343343
macro_rules! mul_impl {
344344
($($t:ty)*) => ($(
345345
#[stable(feature = "rust1", since = "1.0.0")]
346-
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
346+
#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")]
347347
impl const Mul for $t {
348348
type Output = $t;
349349

@@ -453,7 +453,7 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128
453453
/// ```
454454
#[lang = "div"]
455455
#[stable(feature = "rust1", since = "1.0.0")]
456-
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
456+
#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")]
457457
#[diagnostic::on_unimplemented(
458458
message = "cannot divide `{Self}` by `{Rhs}`",
459459
label = "no implementation for `{Self} / {Rhs}`"
@@ -487,7 +487,7 @@ macro_rules! div_impl_integer {
487487
///
488488
#[doc = $panic]
489489
#[stable(feature = "rust1", since = "1.0.0")]
490-
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
490+
#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")]
491491
impl const Div for $t {
492492
type Output = $t;
493493

@@ -509,7 +509,7 @@ div_impl_integer! {
509509
macro_rules! div_impl_float {
510510
($($t:ty)*) => ($(
511511
#[stable(feature = "rust1", since = "1.0.0")]
512-
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
512+
#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")]
513513
impl const Div for $t {
514514
type Output = $t;
515515

@@ -561,7 +561,7 @@ div_impl_float! { f16 f32 f64 f128 }
561561
/// ```
562562
#[lang = "rem"]
563563
#[stable(feature = "rust1", since = "1.0.0")]
564-
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
564+
#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")]
565565
#[diagnostic::on_unimplemented(
566566
message = "cannot calculate the remainder of `{Self}` divided by `{Rhs}`",
567567
label = "no implementation for `{Self} % {Rhs}`"
@@ -595,7 +595,7 @@ macro_rules! rem_impl_integer {
595595
///
596596
#[doc = $panic]
597597
#[stable(feature = "rust1", since = "1.0.0")]
598-
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
598+
#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")]
599599
impl const Rem for $t {
600600
type Output = $t;
601601

@@ -632,7 +632,7 @@ macro_rules! rem_impl_float {
632632
/// assert_eq!(x % y, remainder);
633633
/// ```
634634
#[stable(feature = "rust1", since = "1.0.0")]
635-
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
635+
#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")]
636636
impl const Rem for $t {
637637
type Output = $t;
638638

@@ -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_arith_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_arith_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_arith_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_arith_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_arith_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_arith_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_arith_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_arith_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_arith_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_arith_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_arith_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_arith_ops", issue = "143802")]
1046+
impl const RemAssign for $t {
10291047
#[inline]
10301048
#[track_caller]
10311049
fn rem_assign(&mut self, other: $t) { *self %= other }

src/tools/clippy/tests/ui/assign_ops.fixed

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(clippy::useless_vec)]
22
#![warn(clippy::assign_op_pattern)]
3-
#![feature(const_trait_impl, const_ops)]
3+
#![feature(const_arith_ops)]
4+
#![feature(const_trait_impl)]
45

56
use core::num::Wrapping;
67
use std::ops::{Mul, MulAssign};
@@ -75,6 +76,7 @@ impl MulAssign<i64> for Wrap {
7576
}
7677
}
7778

79+
#[clippy::msrv = "1.88.0"]
7880
mod issue14871 {
7981

8082
use std::ops::{Add, AddAssign};

src/tools/clippy/tests/ui/assign_ops.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(clippy::useless_vec)]
22
#![warn(clippy::assign_op_pattern)]
3-
#![feature(const_trait_impl, const_ops)]
3+
#![feature(const_arith_ops)]
4+
#![feature(const_trait_impl)]
45

56
use core::num::Wrapping;
67
use std::ops::{Mul, MulAssign};
@@ -75,6 +76,7 @@ impl MulAssign<i64> for Wrap {
7576
}
7677
}
7778

79+
#[clippy::msrv = "1.88.0"]
7880
mod issue14871 {
7981

8082
use std::ops::{Add, AddAssign};

src/tools/clippy/tests/ui/assign_ops.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: manual implementation of an assign operation
2-
--> tests/ui/assign_ops.rs:10:5
2+
--> tests/ui/assign_ops.rs:11:5
33
|
44
LL | a = a + 1;
55
| ^^^^^^^^^ help: replace it with: `a += 1`
@@ -8,67 +8,67 @@ LL | a = a + 1;
88
= help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]`
99

1010
error: manual implementation of an assign operation
11-
--> tests/ui/assign_ops.rs:12:5
11+
--> tests/ui/assign_ops.rs:13:5
1212
|
1313
LL | a = 1 + a;
1414
| ^^^^^^^^^ help: replace it with: `a += 1`
1515

1616
error: manual implementation of an assign operation
17-
--> tests/ui/assign_ops.rs:14:5
17+
--> tests/ui/assign_ops.rs:15:5
1818
|
1919
LL | a = a - 1;
2020
| ^^^^^^^^^ help: replace it with: `a -= 1`
2121

2222
error: manual implementation of an assign operation
23-
--> tests/ui/assign_ops.rs:16:5
23+
--> tests/ui/assign_ops.rs:17:5
2424
|
2525
LL | a = a * 99;
2626
| ^^^^^^^^^^ help: replace it with: `a *= 99`
2727

2828
error: manual implementation of an assign operation
29-
--> tests/ui/assign_ops.rs:18:5
29+
--> tests/ui/assign_ops.rs:19:5
3030
|
3131
LL | a = 42 * a;
3232
| ^^^^^^^^^^ help: replace it with: `a *= 42`
3333

3434
error: manual implementation of an assign operation
35-
--> tests/ui/assign_ops.rs:20:5
35+
--> tests/ui/assign_ops.rs:21:5
3636
|
3737
LL | a = a / 2;
3838
| ^^^^^^^^^ help: replace it with: `a /= 2`
3939

4040
error: manual implementation of an assign operation
41-
--> tests/ui/assign_ops.rs:22:5
41+
--> tests/ui/assign_ops.rs:23:5
4242
|
4343
LL | a = a % 5;
4444
| ^^^^^^^^^ help: replace it with: `a %= 5`
4545

4646
error: manual implementation of an assign operation
47-
--> tests/ui/assign_ops.rs:24:5
47+
--> tests/ui/assign_ops.rs:25:5
4848
|
4949
LL | a = a & 1;
5050
| ^^^^^^^^^ help: replace it with: `a &= 1`
5151

5252
error: manual implementation of an assign operation
53-
--> tests/ui/assign_ops.rs:31:5
53+
--> tests/ui/assign_ops.rs:32:5
5454
|
5555
LL | s = s + "bla";
5656
| ^^^^^^^^^^^^^ help: replace it with: `s += "bla"`
5757

5858
error: manual implementation of an assign operation
59-
--> tests/ui/assign_ops.rs:36:5
59+
--> tests/ui/assign_ops.rs:37:5
6060
|
6161
LL | a = a + Wrapping(1u32);
6262
| ^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a += Wrapping(1u32)`
6363

6464
error: manual implementation of an assign operation
65-
--> tests/ui/assign_ops.rs:39:5
65+
--> tests/ui/assign_ops.rs:40:5
6666
|
6767
LL | v[0] = v[0] + v[1];
6868
| ^^^^^^^^^^^^^^^^^^ help: replace it with: `v[0] += v[1]`
6969

7070
error: manual implementation of an assign operation
71-
--> tests/ui/assign_ops.rs:52:5
71+
--> tests/ui/assign_ops.rs:53:5
7272
|
7373
LL | buf = buf + cows.clone();
7474
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()`

tests/ui/traits/const-traits/call-const-trait-method-pass.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#![feature(const_trait_impl, const_ops, const_cmp)]
1+
#![feature(const_arith_ops)]
2+
#![feature(const_cmp)]
3+
#![feature(const_trait_impl)]
24
//@ check-pass
35

46
struct Int(i32);

tests/ui/traits/const-traits/const-and-non-const-impl.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//@ known-bug: #110395
22

3-
#![feature(const_trait_impl, const_ops)]
3+
#![feature(const_arith_ops)]
4+
#![feature(const_trait_impl)]
45

56
pub struct Int(i32);
67

0 commit comments

Comments
 (0)