Skip to content

Commit 4b539b0

Browse files
committed
Add more const_trait annotations
1 parent be65e03 commit 4b539b0

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

library/core/src/convert/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ pub const fn identity<T>(x: T) -> T {
155155
/// ```
156156
#[stable(feature = "rust1", since = "1.0.0")]
157157
#[cfg_attr(not(test), rustc_diagnostic_item = "AsRef")]
158+
#[const_trait]
158159
pub trait AsRef<T: ?Sized> {
159160
/// Converts this type into a shared reference of the (usually inferred) input type.
160161
#[stable(feature = "rust1", since = "1.0.0")]
@@ -197,6 +198,7 @@ pub trait AsRef<T: ?Sized> {
197198
/// [`Box<T>`]: ../../std/boxed/struct.Box.html
198199
#[stable(feature = "rust1", since = "1.0.0")]
199200
#[cfg_attr(not(test), rustc_diagnostic_item = "AsMut")]
201+
#[const_trait]
200202
pub trait AsMut<T: ?Sized> {
201203
/// Converts this type into a mutable reference of the (usually inferred) input type.
202204
#[stable(feature = "rust1", since = "1.0.0")]
@@ -273,6 +275,7 @@ pub trait AsMut<T: ?Sized> {
273275
/// [`Vec`]: ../../std/vec/struct.Vec.html
274276
#[rustc_diagnostic_item = "Into"]
275277
#[stable(feature = "rust1", since = "1.0.0")]
278+
#[const_trait]
276279
pub trait Into<T>: Sized {
277280
/// Converts this type into the (usually inferred) input type.
278281
#[must_use]
@@ -393,6 +396,7 @@ pub trait From<T>: Sized {
393396
/// [`Into`], see there for details.
394397
#[rustc_diagnostic_item = "TryInto"]
395398
#[stable(feature = "try_from", since = "1.34.0")]
399+
#[const_trait]
396400
pub trait TryInto<T>: Sized {
397401
/// The type returned in the event of a conversion error.
398402
#[stable(feature = "try_from", since = "1.34.0")]
@@ -469,6 +473,7 @@ pub trait TryInto<T>: Sized {
469473
/// [`try_from`]: TryFrom::try_from
470474
#[rustc_diagnostic_item = "TryFrom"]
471475
#[stable(feature = "try_from", since = "1.34.0")]
476+
#[const_trait]
472477
pub trait TryFrom<T>: Sized {
473478
/// The type returned in the event of a conversion error.
474479
#[stable(feature = "try_from", since = "1.34.0")]

library/core/src/ops/arith.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
)
9898
)]
9999
#[doc(alias = "+")]
100+
#[const_trait]
100101
pub trait Add<Rhs = Self> {
101102
/// The resulting type after applying the `+` operator.
102103
#[stable(feature = "rust1", since = "1.0.0")]
@@ -204,6 +205,7 @@ add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
204205
label = "no implementation for `{Self} - {Rhs}`"
205206
)]
206207
#[doc(alias = "-")]
208+
#[const_trait]
207209
pub trait Sub<Rhs = Self> {
208210
/// The resulting type after applying the `-` operator.
209211
#[stable(feature = "rust1", since = "1.0.0")]
@@ -333,6 +335,7 @@ sub_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
333335
label = "no implementation for `{Self} * {Rhs}`"
334336
)]
335337
#[doc(alias = "*")]
338+
#[const_trait]
336339
pub trait Mul<Rhs = Self> {
337340
/// The resulting type after applying the `*` operator.
338341
#[stable(feature = "rust1", since = "1.0.0")]
@@ -466,6 +469,7 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
466469
label = "no implementation for `{Self} / {Rhs}`"
467470
)]
468471
#[doc(alias = "/")]
472+
#[const_trait]
469473
pub trait Div<Rhs = Self> {
470474
/// The resulting type after applying the `/` operator.
471475
#[stable(feature = "rust1", since = "1.0.0")]
@@ -568,6 +572,7 @@ div_impl_float! { f32 f64 }
568572
label = "no implementation for `{Self} % {Rhs}`"
569573
)]
570574
#[doc(alias = "%")]
575+
#[const_trait]
571576
pub trait Rem<Rhs = Self> {
572577
/// The resulting type after applying the `%` operator.
573578
#[stable(feature = "rust1", since = "1.0.0")]
@@ -682,6 +687,7 @@ rem_impl_float! { f32 f64 }
682687
#[lang = "neg"]
683688
#[stable(feature = "rust1", since = "1.0.0")]
684689
#[doc(alias = "-")]
690+
#[const_trait]
685691
pub trait Neg {
686692
/// The resulting type after applying the `-` operator.
687693
#[stable(feature = "rust1", since = "1.0.0")]
@@ -755,6 +761,7 @@ neg_impl! { isize i8 i16 i32 i64 i128 f32 f64 }
755761
)]
756762
#[doc(alias = "+")]
757763
#[doc(alias = "+=")]
764+
#[const_trait]
758765
pub trait AddAssign<Rhs = Self> {
759766
/// Performs the `+=` operation.
760767
///
@@ -822,6 +829,7 @@ add_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
822829
)]
823830
#[doc(alias = "-")]
824831
#[doc(alias = "-=")]
832+
#[const_trait]
825833
pub trait SubAssign<Rhs = Self> {
826834
/// Performs the `-=` operation.
827835
///
@@ -880,6 +888,7 @@ sub_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
880888
)]
881889
#[doc(alias = "*")]
882890
#[doc(alias = "*=")]
891+
#[const_trait]
883892
pub trait MulAssign<Rhs = Self> {
884893
/// Performs the `*=` operation.
885894
///

library/core/src/ops/bit.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ impl const Not for ! {
144144
message = "no implementation for `{Self} & {Rhs}`",
145145
label = "no implementation for `{Self} & {Rhs}`"
146146
)]
147+
#[const_trait]
147148
pub trait BitAnd<Rhs = Self> {
148149
/// The resulting type after applying the `&` operator.
149150
#[stable(feature = "rust1", since = "1.0.0")]
@@ -245,6 +246,7 @@ bitand_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
245246
message = "no implementation for `{Self} | {Rhs}`",
246247
label = "no implementation for `{Self} | {Rhs}`"
247248
)]
249+
#[const_trait]
248250
pub trait BitOr<Rhs = Self> {
249251
/// The resulting type after applying the `|` operator.
250252
#[stable(feature = "rust1", since = "1.0.0")]
@@ -346,6 +348,7 @@ bitor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
346348
message = "no implementation for `{Self} ^ {Rhs}`",
347349
label = "no implementation for `{Self} ^ {Rhs}`"
348350
)]
351+
#[const_trait]
349352
pub trait BitXor<Rhs = Self> {
350353
/// The resulting type after applying the `^` operator.
351354
#[stable(feature = "rust1", since = "1.0.0")]
@@ -446,6 +449,7 @@ bitxor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
446449
message = "no implementation for `{Self} << {Rhs}`",
447450
label = "no implementation for `{Self} << {Rhs}`"
448451
)]
452+
#[const_trait]
449453
pub trait Shl<Rhs = Self> {
450454
/// The resulting type after applying the `<<` operator.
451455
#[stable(feature = "rust1", since = "1.0.0")]
@@ -565,6 +569,7 @@ shl_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 isize i128 }
565569
message = "no implementation for `{Self} >> {Rhs}`",
566570
label = "no implementation for `{Self} >> {Rhs}`"
567571
)]
572+
#[const_trait]
568573
pub trait Shr<Rhs = Self> {
569574
/// The resulting type after applying the `>>` operator.
570575
#[stable(feature = "rust1", since = "1.0.0")]
@@ -693,6 +698,7 @@ shr_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
693698
message = "no implementation for `{Self} &= {Rhs}`",
694699
label = "no implementation for `{Self} &= {Rhs}`"
695700
)]
701+
#[const_trait]
696702
pub trait BitAndAssign<Rhs = Self> {
697703
/// Performs the `&=` operation.
698704
///
@@ -765,6 +771,7 @@ bitand_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
765771
message = "no implementation for `{Self} |= {Rhs}`",
766772
label = "no implementation for `{Self} |= {Rhs}`"
767773
)]
774+
#[const_trait]
768775
pub trait BitOrAssign<Rhs = Self> {
769776
/// Performs the `|=` operation.
770777
///
@@ -837,6 +844,7 @@ bitor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
837844
message = "no implementation for `{Self} ^= {Rhs}`",
838845
label = "no implementation for `{Self} ^= {Rhs}`"
839846
)]
847+
#[const_trait]
840848
pub trait BitXorAssign<Rhs = Self> {
841849
/// Performs the `^=` operation.
842850
///

library/core/src/ops/deref.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
#[doc(alias = "&*")]
6262
#[stable(feature = "rust1", since = "1.0.0")]
6363
#[rustc_diagnostic_item = "Deref"]
64-
#[const_trait]
64+
#[cfg_attr(not(bootstrap), const_trait)]
6565
pub trait Deref {
6666
/// The resulting type after dereferencing.
6767
#[stable(feature = "rust1", since = "1.0.0")]
@@ -170,6 +170,7 @@ impl<T: ?Sized> const Deref for &mut T {
170170
#[lang = "deref_mut"]
171171
#[doc(alias = "*")]
172172
#[stable(feature = "rust1", since = "1.0.0")]
173+
#[const_trait]
173174
pub trait DerefMut: Deref {
174175
/// Mutably dereferences the value.
175176
#[stable(feature = "rust1", since = "1.0.0")]

library/core/src/ops/index.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#[doc(alias = "]")]
5656
#[doc(alias = "[")]
5757
#[doc(alias = "[]")]
58-
#[const_trait]
58+
#[cfg_attr(not(bootstrap), const_trait)]
5959
pub trait Index<Idx: ?Sized> {
6060
/// The returned type after indexing.
6161
#[stable(feature = "rust1", since = "1.0.0")]
@@ -164,7 +164,7 @@ see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#ind
164164
#[doc(alias = "[")]
165165
#[doc(alias = "]")]
166166
#[doc(alias = "[]")]
167-
#[const_trait]
167+
#[cfg_attr(not(bootstrap), const_trait)]
168168
pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
169169
/// Performs the mutable indexing (`container[index]`) operation.
170170
///

0 commit comments

Comments
 (0)