Skip to content

Commit ff1fdff

Browse files
committed
Make bit ops traits const
1 parent 6c0a912 commit ff1fdff

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed

library/core/src/ops/bit.rs

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#[lang = "not"]
3232
#[stable(feature = "rust1", since = "1.0.0")]
3333
#[doc(alias = "!")]
34+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
35+
#[const_trait]
3436
pub trait Not {
3537
/// The resulting type after applying the `!` operator.
3638
#[stable(feature = "rust1", since = "1.0.0")]
@@ -54,7 +56,8 @@ pub trait Not {
5456
macro_rules! not_impl {
5557
($($t:ty)*) => ($(
5658
#[stable(feature = "rust1", since = "1.0.0")]
57-
impl Not for $t {
59+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
60+
impl const Not for $t {
5861
type Output = $t;
5962

6063
#[inline]
@@ -68,7 +71,8 @@ macro_rules! not_impl {
6871
not_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
6972

7073
#[stable(feature = "not_never", since = "1.60.0")]
71-
impl Not for ! {
74+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
75+
impl const Not for ! {
7276
type Output = !;
7377

7478
#[inline]
@@ -141,6 +145,8 @@ impl Not for ! {
141145
message = "no implementation for `{Self} & {Rhs}`",
142146
label = "no implementation for `{Self} & {Rhs}`"
143147
)]
148+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
149+
#[const_trait]
144150
pub trait BitAnd<Rhs = Self> {
145151
/// The resulting type after applying the `&` operator.
146152
#[stable(feature = "rust1", since = "1.0.0")]
@@ -164,7 +170,8 @@ pub trait BitAnd<Rhs = Self> {
164170
macro_rules! bitand_impl {
165171
($($t:ty)*) => ($(
166172
#[stable(feature = "rust1", since = "1.0.0")]
167-
impl BitAnd for $t {
173+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
174+
impl const BitAnd for $t {
168175
type Output = $t;
169176

170177
#[inline]
@@ -241,6 +248,8 @@ bitand_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
241248
message = "no implementation for `{Self} | {Rhs}`",
242249
label = "no implementation for `{Self} | {Rhs}`"
243250
)]
251+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
252+
#[const_trait]
244253
pub trait BitOr<Rhs = Self> {
245254
/// The resulting type after applying the `|` operator.
246255
#[stable(feature = "rust1", since = "1.0.0")]
@@ -264,7 +273,8 @@ pub trait BitOr<Rhs = Self> {
264273
macro_rules! bitor_impl {
265274
($($t:ty)*) => ($(
266275
#[stable(feature = "rust1", since = "1.0.0")]
267-
impl BitOr for $t {
276+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
277+
impl const BitOr for $t {
268278
type Output = $t;
269279

270280
#[inline]
@@ -341,6 +351,8 @@ bitor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
341351
message = "no implementation for `{Self} ^ {Rhs}`",
342352
label = "no implementation for `{Self} ^ {Rhs}`"
343353
)]
354+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
355+
#[const_trait]
344356
pub trait BitXor<Rhs = Self> {
345357
/// The resulting type after applying the `^` operator.
346358
#[stable(feature = "rust1", since = "1.0.0")]
@@ -364,7 +376,8 @@ pub trait BitXor<Rhs = Self> {
364376
macro_rules! bitxor_impl {
365377
($($t:ty)*) => ($(
366378
#[stable(feature = "rust1", since = "1.0.0")]
367-
impl BitXor for $t {
379+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
380+
impl const BitXor for $t {
368381
type Output = $t;
369382

370383
#[inline]
@@ -440,6 +453,8 @@ bitxor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
440453
message = "no implementation for `{Self} << {Rhs}`",
441454
label = "no implementation for `{Self} << {Rhs}`"
442455
)]
456+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
457+
#[const_trait]
443458
pub trait Shl<Rhs = Self> {
444459
/// The resulting type after applying the `<<` operator.
445460
#[stable(feature = "rust1", since = "1.0.0")]
@@ -461,7 +476,8 @@ pub trait Shl<Rhs = Self> {
461476
macro_rules! shl_impl {
462477
($t:ty, $f:ty) => {
463478
#[stable(feature = "rust1", since = "1.0.0")]
464-
impl Shl<$f> for $t {
479+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
480+
impl const Shl<$f> for $t {
465481
type Output = $t;
466482

467483
#[inline]
@@ -558,6 +574,8 @@ shl_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
558574
message = "no implementation for `{Self} >> {Rhs}`",
559575
label = "no implementation for `{Self} >> {Rhs}`"
560576
)]
577+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
578+
#[const_trait]
561579
pub trait Shr<Rhs = Self> {
562580
/// The resulting type after applying the `>>` operator.
563581
#[stable(feature = "rust1", since = "1.0.0")]
@@ -579,7 +597,8 @@ pub trait Shr<Rhs = Self> {
579597
macro_rules! shr_impl {
580598
($t:ty, $f:ty) => {
581599
#[stable(feature = "rust1", since = "1.0.0")]
582-
impl Shr<$f> for $t {
600+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
601+
impl const Shr<$f> for $t {
583602
type Output = $t;
584603

585604
#[inline]
@@ -685,6 +704,8 @@ shr_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
685704
message = "no implementation for `{Self} &= {Rhs}`",
686705
label = "no implementation for `{Self} &= {Rhs}`"
687706
)]
707+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
708+
#[const_trait]
688709
pub trait BitAndAssign<Rhs = Self> {
689710
/// Performs the `&=` operation.
690711
///
@@ -714,7 +735,8 @@ pub trait BitAndAssign<Rhs = Self> {
714735
macro_rules! bitand_assign_impl {
715736
($($t:ty)+) => ($(
716737
#[stable(feature = "op_assign_traits", since = "1.8.0")]
717-
impl BitAndAssign for $t {
738+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
739+
impl const BitAndAssign for $t {
718740
#[inline]
719741
fn bitand_assign(&mut self, other: $t) { *self &= other }
720742
}
@@ -756,6 +778,8 @@ bitand_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
756778
message = "no implementation for `{Self} |= {Rhs}`",
757779
label = "no implementation for `{Self} |= {Rhs}`"
758780
)]
781+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
782+
#[const_trait]
759783
pub trait BitOrAssign<Rhs = Self> {
760784
/// Performs the `|=` operation.
761785
///
@@ -785,7 +809,8 @@ pub trait BitOrAssign<Rhs = Self> {
785809
macro_rules! bitor_assign_impl {
786810
($($t:ty)+) => ($(
787811
#[stable(feature = "op_assign_traits", since = "1.8.0")]
788-
impl BitOrAssign for $t {
812+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
813+
impl const BitOrAssign for $t {
789814
#[inline]
790815
fn bitor_assign(&mut self, other: $t) { *self |= other }
791816
}
@@ -827,6 +852,8 @@ bitor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
827852
message = "no implementation for `{Self} ^= {Rhs}`",
828853
label = "no implementation for `{Self} ^= {Rhs}`"
829854
)]
855+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
856+
#[const_trait]
830857
pub trait BitXorAssign<Rhs = Self> {
831858
/// Performs the `^=` operation.
832859
///
@@ -856,7 +883,8 @@ pub trait BitXorAssign<Rhs = Self> {
856883
macro_rules! bitxor_assign_impl {
857884
($($t:ty)+) => ($(
858885
#[stable(feature = "op_assign_traits", since = "1.8.0")]
859-
impl BitXorAssign for $t {
886+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
887+
impl const BitXorAssign for $t {
860888
#[inline]
861889
fn bitxor_assign(&mut self, other: $t) { *self ^= other }
862890
}
@@ -896,6 +924,8 @@ bitxor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
896924
message = "no implementation for `{Self} <<= {Rhs}`",
897925
label = "no implementation for `{Self} <<= {Rhs}`"
898926
)]
927+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
928+
#[const_trait]
899929
pub trait ShlAssign<Rhs = Self> {
900930
/// Performs the `<<=` operation.
901931
///
@@ -917,7 +947,8 @@ pub trait ShlAssign<Rhs = Self> {
917947
macro_rules! shl_assign_impl {
918948
($t:ty, $f:ty) => {
919949
#[stable(feature = "op_assign_traits", since = "1.8.0")]
920-
impl ShlAssign<$f> for $t {
950+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
951+
impl const ShlAssign<$f> for $t {
921952
#[inline]
922953
#[rustc_inherit_overflow_checks]
923954
fn shl_assign(&mut self, other: $f) {
@@ -978,6 +1009,8 @@ shl_assign_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
9781009
message = "no implementation for `{Self} >>= {Rhs}`",
9791010
label = "no implementation for `{Self} >>= {Rhs}`"
9801011
)]
1012+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
1013+
#[const_trait]
9811014
pub trait ShrAssign<Rhs = Self> {
9821015
/// Performs the `>>=` operation.
9831016
///
@@ -999,7 +1032,8 @@ pub trait ShrAssign<Rhs = Self> {
9991032
macro_rules! shr_assign_impl {
10001033
($t:ty, $f:ty) => {
10011034
#[stable(feature = "op_assign_traits", since = "1.8.0")]
1002-
impl ShrAssign<$f> for $t {
1035+
#[rustc_const_unstable(feature = "const_bitops", issue = "144119")]
1036+
impl const ShrAssign<$f> for $t {
10031037
#[inline]
10041038
#[rustc_inherit_overflow_checks]
10051039
fn shr_assign(&mut self, other: $f) {

0 commit comments

Comments
 (0)