diff --git a/library/core/src/internal_macros.rs b/library/core/src/internal_macros.rs index 2aaefba2468bb..e643d589a0933 100644 --- a/library/core/src/internal_macros.rs +++ b/library/core/src/internal_macros.rs @@ -1,13 +1,10 @@ // implements the unary operator "op &T" // based on "op T" where T is expected to be `Copy`able macro_rules! forward_ref_unop { - (impl $imp:ident, $method:ident for $t:ty) => { - forward_ref_unop!(impl $imp, $method for $t, - #[stable(feature = "rust1", since = "1.0.0")]); - }; - (impl $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => { - #[$attr] - impl $imp for &$t { + // FIXME: use macro_named_capture_groups to directly do impl $const(const)? instead + (impl $imp:ident, $method:ident for $t:ty, $(#[$attr:meta])+ $(, $const:tt)?) => { + $(#[$attr])+ + impl $($const)? $imp for &$t { type Output = <$t as $imp>::Output; #[inline] @@ -21,13 +18,10 @@ macro_rules! forward_ref_unop { // implements binary operators "&T op U", "T op &U", "&T op &U" // based on "T op U" where T and U are expected to be `Copy`able macro_rules! forward_ref_binop { - (impl $imp:ident, $method:ident for $t:ty, $u:ty) => { - forward_ref_binop!(impl $imp, $method for $t, $u, - #[stable(feature = "rust1", since = "1.0.0")]); - }; - (impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => { - #[$attr] - impl<'a> $imp<$u> for &'a $t { + // FIXME: use macro_named_capture_groups to directly do impl $const(const)? instead + (impl $imp:ident, $method:ident for $t:ty, $u:ty, $(#[$attr:meta])+ $(, $const:tt)?) => { + $(#[$attr])+ + impl<'a> $($const)? $imp<$u> for &'a $t { type Output = <$t as $imp<$u>>::Output; #[inline] @@ -37,8 +31,8 @@ macro_rules! forward_ref_binop { } } - #[$attr] - impl $imp<&$u> for $t { + $(#[$attr])+ + impl $($const)? $imp<&$u> for $t { type Output = <$t as $imp<$u>>::Output; #[inline] @@ -48,8 +42,8 @@ macro_rules! forward_ref_binop { } } - #[$attr] - impl $imp<&$u> for &$t { + $(#[$attr])+ + impl $($const)? $imp<&$u> for &$t { type Output = <$t as $imp<$u>>::Output; #[inline] @@ -64,13 +58,10 @@ macro_rules! forward_ref_binop { // implements "T op= &U", based on "T op= U" // where U is expected to be `Copy`able macro_rules! forward_ref_op_assign { - (impl $imp:ident, $method:ident for $t:ty, $u:ty) => { - forward_ref_op_assign!(impl $imp, $method for $t, $u, - #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]); - }; - (impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => { - #[$attr] - impl $imp<&$u> for $t { + // FIXME: use macro_named_capture_groups to directly do impl $const(const)? instead + (impl $imp:ident, $method:ident for $t:ty, $u:ty, $(#[$attr:meta])+ $(, $const:tt)?) => { + $(#[$attr])+ + impl $($const)? $imp<&$u> for $t { #[inline] #[track_caller] fn $method(&mut self, other: &$u) { diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 4460e430aecfa..1e7ad10245e33 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -109,7 +109,8 @@ impl fmt::UpperHex for Saturating { // // *self = *self << other; // // } // // } -// // forward_ref_op_assign! { impl ShlAssign, shl_assign for Saturating<$t>, $f } +// // forward_ref_op_assign! { impl ShlAssign, shl_assign for Saturating<$t>, $f, +// // #[unstable(feature = "saturating_int_impl", issue = "87920")] } // // #[unstable(feature = "saturating_int_impl", issue = "87920")] // impl Shr<$f> for Saturating<$t> { @@ -134,7 +135,8 @@ impl fmt::UpperHex for Saturating { // *self = *self >> other; // } // } -// forward_ref_op_assign! { impl ShrAssign, shr_assign for Saturating<$t>, $f } +// forward_ref_op_assign! { impl ShrAssign, shr_assign for Saturating<$t>, $f, +// #[unstable(feature = "saturating_int_impl", issue = "87920")] } // }; // } // @@ -159,7 +161,8 @@ impl fmt::UpperHex for Saturating { // *self = *self << other; // } // } -// forward_ref_op_assign! { impl ShlAssign, shl_assign for Saturating<$t>, $f } +// forward_ref_op_assign! { impl ShlAssign, shl_assign for Saturating<$t>, $f, +// #[unstable(feature = "saturating_int_impl", issue = "87920")] } // // #[unstable(feature = "saturating_int_impl", issue = "87920")] // impl Shr<$f> for Saturating<$t> { @@ -180,7 +183,8 @@ impl fmt::UpperHex for Saturating { // *self = *self >> other; // } // } -// forward_ref_op_assign! { impl ShrAssign, shr_assign for Saturating<$t>, $f } +// forward_ref_op_assign! { impl ShrAssign, shr_assign for Saturating<$t>, $f, +// #[unstable(feature = "saturating_int_impl", issue = "87920")] } // }; // } // @@ -209,7 +213,8 @@ impl fmt::UpperHex for Saturating { macro_rules! saturating_impl { ($($t:ty)*) => ($( #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl Add for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const Add for Saturating<$t> { type Output = Saturating<$t>; #[inline] @@ -218,28 +223,39 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Add, add for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl AddAssign for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const AddAssign for Saturating<$t> { #[inline] fn add_assign(&mut self, other: Saturating<$t>) { *self = *self + other; } } - forward_ref_op_assign! { impl AddAssign, add_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl AddAssign, add_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] - impl AddAssign<$t> for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const AddAssign<$t> for Saturating<$t> { #[inline] fn add_assign(&mut self, other: $t) { *self = *self + Saturating(other); } } - forward_ref_op_assign! { impl AddAssign, add_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl AddAssign, add_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl Sub for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const Sub for Saturating<$t> { type Output = Saturating<$t>; #[inline] @@ -248,28 +264,39 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Sub, sub for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl SubAssign for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const SubAssign for Saturating<$t> { #[inline] fn sub_assign(&mut self, other: Saturating<$t>) { *self = *self - other; } } - forward_ref_op_assign! { impl SubAssign, sub_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl SubAssign, sub_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] - impl SubAssign<$t> for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const SubAssign<$t> for Saturating<$t> { #[inline] fn sub_assign(&mut self, other: $t) { *self = *self - Saturating(other); } } - forward_ref_op_assign! { impl SubAssign, sub_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl SubAssign, sub_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl Mul for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const Mul for Saturating<$t> { type Output = Saturating<$t>; #[inline] @@ -278,25 +305,35 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Mul, mul for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl MulAssign for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const MulAssign for Saturating<$t> { #[inline] fn mul_assign(&mut self, other: Saturating<$t>) { *self = *self * other; } } - forward_ref_op_assign! { impl MulAssign, mul_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl MulAssign, mul_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] - impl MulAssign<$t> for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const MulAssign<$t> for Saturating<$t> { #[inline] fn mul_assign(&mut self, other: $t) { *self = *self * Saturating(other); } } - forward_ref_op_assign! { impl MulAssign, mul_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl MulAssign, mul_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } /// # Examples /// @@ -314,7 +351,8 @@ macro_rules! saturating_impl { #[doc = concat!("let _ = Saturating(0", stringify!($t), ") / Saturating(0);")] /// ``` #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl Div for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const Div for Saturating<$t> { type Output = Saturating<$t>; #[inline] @@ -323,29 +361,39 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Div, div for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } - + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl DivAssign for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const DivAssign for Saturating<$t> { #[inline] fn div_assign(&mut self, other: Saturating<$t>) { *self = *self / other; } } - forward_ref_op_assign! { impl DivAssign, div_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl DivAssign, div_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] - impl DivAssign<$t> for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const DivAssign<$t> for Saturating<$t> { #[inline] fn div_assign(&mut self, other: $t) { *self = *self / Saturating(other); } } - forward_ref_op_assign! { impl DivAssign, div_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl DivAssign, div_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl Rem for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const Rem for Saturating<$t> { type Output = Saturating<$t>; #[inline] @@ -354,25 +402,35 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Rem, rem for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl RemAssign for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const RemAssign for Saturating<$t> { #[inline] fn rem_assign(&mut self, other: Saturating<$t>) { *self = *self % other; } } - forward_ref_op_assign! { impl RemAssign, rem_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl RemAssign, rem_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] - impl RemAssign<$t> for Saturating<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const RemAssign<$t> for Saturating<$t> { #[inline] fn rem_assign(&mut self, other: $t) { *self = *self % Saturating(other); } } - forward_ref_op_assign! { impl RemAssign, rem_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl RemAssign, rem_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "saturating_int_impl", since = "1.74.0")] impl Not for Saturating<$t> { @@ -384,7 +442,7 @@ macro_rules! saturating_impl { } } forward_ref_unop! { impl Not, not for Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] impl BitXor for Saturating<$t> { @@ -396,7 +454,7 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl BitXor, bitxor for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] impl BitXorAssign for Saturating<$t> { @@ -405,7 +463,8 @@ macro_rules! saturating_impl { *self = *self ^ other; } } - forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] impl BitXorAssign<$t> for Saturating<$t> { @@ -414,7 +473,8 @@ macro_rules! saturating_impl { *self = *self ^ Saturating(other); } } - forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] impl BitOr for Saturating<$t> { @@ -426,7 +486,7 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl BitOr, bitor for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] impl BitOrAssign for Saturating<$t> { @@ -435,7 +495,8 @@ macro_rules! saturating_impl { *self = *self | other; } } - forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] impl BitOrAssign<$t> for Saturating<$t> { @@ -444,7 +505,8 @@ macro_rules! saturating_impl { *self = *self | Saturating(other); } } - forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] impl BitAnd for Saturating<$t> { @@ -456,7 +518,7 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl BitAnd, bitand for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] impl BitAndAssign for Saturating<$t> { @@ -465,7 +527,8 @@ macro_rules! saturating_impl { *self = *self & other; } } - forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] impl BitAndAssign<$t> for Saturating<$t> { @@ -474,7 +537,8 @@ macro_rules! saturating_impl { *self = *self & Saturating(other); } } - forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] } )*) } @@ -939,7 +1003,7 @@ macro_rules! saturating_int_impl_signed { } } forward_ref_unop! { impl Neg, neg for Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] } )*) } diff --git a/library/core/src/num/wrapping.rs b/library/core/src/num/wrapping.rs index c460f38bd2e4d..3f04dcd4ff95e 100644 --- a/library/core/src/num/wrapping.rs +++ b/library/core/src/num/wrapping.rs @@ -110,7 +110,8 @@ macro_rules! sh_impl_signed { *self = *self << other; } } - forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f } + forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } #[stable(feature = "rust1", since = "1.0.0")] impl Shr<$f> for Wrapping<$t> { @@ -135,7 +136,8 @@ macro_rules! sh_impl_signed { *self = *self >> other; } } - forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f } + forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } }; } @@ -160,7 +162,8 @@ macro_rules! sh_impl_unsigned { *self = *self << other; } } - forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f } + forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } #[stable(feature = "rust1", since = "1.0.0")] impl Shr<$f> for Wrapping<$t> { @@ -181,7 +184,8 @@ macro_rules! sh_impl_unsigned { *self = *self >> other; } } - forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f } + forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } }; } @@ -210,7 +214,8 @@ sh_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize } macro_rules! wrapping_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - impl Add for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const Add for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -219,28 +224,39 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl Add, add for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl AddAssign for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const AddAssign for Wrapping<$t> { #[inline] fn add_assign(&mut self, other: Wrapping<$t>) { *self = *self + other; } } - forward_ref_op_assign! { impl AddAssign, add_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl AddAssign, add_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] - impl AddAssign<$t> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const AddAssign<$t> for Wrapping<$t> { #[inline] fn add_assign(&mut self, other: $t) { *self = *self + Wrapping(other); } } - forward_ref_op_assign! { impl AddAssign, add_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl AddAssign, add_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "rust1", since = "1.0.0")] - impl Sub for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const Sub for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -249,28 +265,39 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl Sub, sub for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl SubAssign for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const SubAssign for Wrapping<$t> { #[inline] fn sub_assign(&mut self, other: Wrapping<$t>) { *self = *self - other; } } - forward_ref_op_assign! { impl SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] - impl SubAssign<$t> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const SubAssign<$t> for Wrapping<$t> { #[inline] fn sub_assign(&mut self, other: $t) { *self = *self - Wrapping(other); } } - forward_ref_op_assign! { impl SubAssign, sub_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl SubAssign, sub_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "rust1", since = "1.0.0")] - impl Mul for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const Mul for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -279,28 +306,39 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl Mul, mul for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl MulAssign for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const MulAssign for Wrapping<$t> { #[inline] fn mul_assign(&mut self, other: Wrapping<$t>) { *self = *self * other; } } - forward_ref_op_assign! { impl MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] - impl MulAssign<$t> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const MulAssign<$t> for Wrapping<$t> { #[inline] fn mul_assign(&mut self, other: $t) { *self = *self * Wrapping(other); } } - forward_ref_op_assign! { impl MulAssign, mul_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl MulAssign, mul_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "wrapping_div", since = "1.3.0")] - impl Div for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const Div for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -309,28 +347,39 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl Div, div for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl DivAssign for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const DivAssign for Wrapping<$t> { #[inline] fn div_assign(&mut self, other: Wrapping<$t>) { *self = *self / other; } } - forward_ref_op_assign! { impl DivAssign, div_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl DivAssign, div_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] - impl DivAssign<$t> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const DivAssign<$t> for Wrapping<$t> { #[inline] fn div_assign(&mut self, other: $t) { *self = *self / Wrapping(other); } } - forward_ref_op_assign! { impl DivAssign, div_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl DivAssign, div_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "wrapping_impls", since = "1.7.0")] - impl Rem for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const Rem for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -339,25 +388,35 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl Rem, rem for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl RemAssign for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const RemAssign for Wrapping<$t> { #[inline] fn rem_assign(&mut self, other: Wrapping<$t>) { *self = *self % other; } } - forward_ref_op_assign! { impl RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] - impl RemAssign<$t> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const RemAssign<$t> for Wrapping<$t> { #[inline] fn rem_assign(&mut self, other: $t) { *self = *self % Wrapping(other); } } - forward_ref_op_assign! { impl RemAssign, rem_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl RemAssign, rem_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } #[stable(feature = "rust1", since = "1.0.0")] impl Not for Wrapping<$t> { @@ -369,7 +428,7 @@ macro_rules! wrapping_impl { } } forward_ref_unop! { impl Not, not for Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] } #[stable(feature = "rust1", since = "1.0.0")] impl BitXor for Wrapping<$t> { @@ -381,7 +440,7 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl BitXor, bitxor for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] impl BitXorAssign for Wrapping<$t> { @@ -390,7 +449,8 @@ macro_rules! wrapping_impl { *self = *self ^ other; } } - forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] impl BitXorAssign<$t> for Wrapping<$t> { @@ -399,7 +459,8 @@ macro_rules! wrapping_impl { *self = *self ^ Wrapping(other); } } - forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } #[stable(feature = "rust1", since = "1.0.0")] impl BitOr for Wrapping<$t> { @@ -411,7 +472,7 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl BitOr, bitor for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] impl BitOrAssign for Wrapping<$t> { @@ -420,7 +481,8 @@ macro_rules! wrapping_impl { *self = *self | other; } } - forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] impl BitOrAssign<$t> for Wrapping<$t> { @@ -429,7 +491,8 @@ macro_rules! wrapping_impl { *self = *self | Wrapping(other); } } - forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } #[stable(feature = "rust1", since = "1.0.0")] impl BitAnd for Wrapping<$t> { @@ -441,7 +504,7 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl BitAnd, bitand for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] impl BitAndAssign for Wrapping<$t> { @@ -450,7 +513,8 @@ macro_rules! wrapping_impl { *self = *self & other; } } - forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] impl BitAndAssign<$t> for Wrapping<$t> { @@ -459,7 +523,8 @@ macro_rules! wrapping_impl { *self = *self & Wrapping(other); } } - forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } #[stable(feature = "wrapping_neg", since = "1.10.0")] impl Neg for Wrapping<$t> { @@ -470,7 +535,7 @@ macro_rules! wrapping_impl { } } forward_ref_unop! { impl Neg, neg for Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] } )*) } diff --git a/library/core/src/ops/arith.rs b/library/core/src/ops/arith.rs index 7d44b1733b9c6..0808d46e2efe8 100644 --- a/library/core/src/ops/arith.rs +++ b/library/core/src/ops/arith.rs @@ -65,7 +65,7 @@ /// ``` #[lang = "add"] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] #[rustc_on_unimplemented( on(all(Self = "{integer}", Rhs = "{float}"), message = "cannot add a float to an integer",), on(all(Self = "{float}", Rhs = "{integer}"), message = "cannot add an integer to a float",), @@ -96,7 +96,7 @@ pub trait Add { macro_rules! add_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] impl const Add for $t { type Output = $t; @@ -106,7 +106,10 @@ macro_rules! add_impl { fn add(self, other: $t) -> $t { self + other } } - forward_ref_binop! { impl Add, add for $t, $t } + forward_ref_binop! { impl Add, add for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } )*) } @@ -179,7 +182,7 @@ add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128 /// ``` #[lang = "sub"] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] #[rustc_on_unimplemented( message = "cannot subtract `{Rhs}` from `{Self}`", label = "no implementation for `{Self} - {Rhs}`", @@ -208,7 +211,7 @@ pub trait Sub { macro_rules! sub_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] impl const Sub for $t { type Output = $t; @@ -218,7 +221,10 @@ macro_rules! sub_impl { fn sub(self, other: $t) -> $t { self - other } } - forward_ref_binop! { impl Sub, sub for $t, $t } + forward_ref_binop! { impl Sub, sub for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } )*) } @@ -313,7 +319,7 @@ sub_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128 /// ``` #[lang = "mul"] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "cannot multiply `{Self}` by `{Rhs}`", label = "no implementation for `{Self} * {Rhs}`" @@ -341,7 +347,7 @@ pub trait Mul { macro_rules! mul_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] impl const Mul for $t { type Output = $t; @@ -351,7 +357,10 @@ macro_rules! mul_impl { fn mul(self, other: $t) -> $t { self * other } } - forward_ref_binop! { impl Mul, mul for $t, $t } + forward_ref_binop! { impl Mul, mul for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } )*) } @@ -450,7 +459,7 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128 /// ``` #[lang = "div"] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "cannot divide `{Self}` by `{Rhs}`", label = "no implementation for `{Self} / {Rhs}`" @@ -484,7 +493,7 @@ macro_rules! div_impl_integer { /// #[doc = $panic] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] impl const Div for $t { type Output = $t; @@ -493,7 +502,10 @@ macro_rules! div_impl_integer { fn div(self, other: $t) -> $t { self / other } } - forward_ref_binop! { impl Div, div for $t, $t } + forward_ref_binop! { impl Div, div for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } )*)*) } @@ -505,7 +517,7 @@ div_impl_integer! { macro_rules! div_impl_float { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] impl const Div for $t { type Output = $t; @@ -513,7 +525,10 @@ macro_rules! div_impl_float { fn div(self, other: $t) -> $t { self / other } } - forward_ref_binop! { impl Div, div for $t, $t } + forward_ref_binop! { impl Div, div for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } )*) } @@ -556,7 +571,7 @@ div_impl_float! { f16 f32 f64 f128 } /// ``` #[lang = "rem"] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "cannot calculate the remainder of `{Self}` divided by `{Rhs}`", label = "no implementation for `{Self} % {Rhs}`" @@ -590,7 +605,7 @@ macro_rules! rem_impl_integer { /// #[doc = $panic] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] impl const Rem for $t { type Output = $t; @@ -599,7 +614,10 @@ macro_rules! rem_impl_integer { fn rem(self, other: $t) -> $t { self % other } } - forward_ref_binop! { impl Rem, rem for $t, $t } + forward_ref_binop! { impl Rem, rem for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } )*)*) } @@ -626,7 +644,7 @@ macro_rules! rem_impl_float { /// assert_eq!(x % y, remainder); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] impl const Rem for $t { type Output = $t; @@ -634,7 +652,10 @@ macro_rules! rem_impl_float { fn rem(self, other: $t) -> $t { self % other } } - forward_ref_binop! { impl Rem, rem for $t, $t } + forward_ref_binop! { impl Rem, rem for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } )*) } @@ -678,7 +699,9 @@ rem_impl_float! { f16 f32 f64 f128 } /// ``` #[lang = "neg"] #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] #[doc(alias = "-")] +#[const_trait] pub trait Neg { /// The resulting type after applying the `-` operator. #[stable(feature = "rust1", since = "1.0.0")] @@ -701,7 +724,8 @@ pub trait Neg { macro_rules! neg_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - impl Neg for $t { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const Neg for $t { type Output = $t; #[inline] @@ -709,7 +733,10 @@ macro_rules! neg_impl { fn neg(self) -> $t { -self } } - forward_ref_unop! { impl Neg, neg for $t } + forward_ref_unop! { impl Neg, neg for $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } )*) } @@ -746,12 +773,14 @@ neg_impl! { isize i8 i16 i32 i64 i128 f16 f32 f64 f128 } /// ``` #[lang = "add_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "cannot add-assign `{Rhs}` to `{Self}`", label = "no implementation for `{Self} += {Rhs}`" )] #[doc(alias = "+")] #[doc(alias = "+=")] +#[const_trait] pub trait AddAssign { /// Performs the `+=` operation. /// @@ -769,14 +798,18 @@ pub trait AddAssign { macro_rules! add_assign_impl { ($($t:ty)+) => ($( #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl AddAssign for $t { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const AddAssign for $t { #[inline] #[track_caller] #[rustc_inherit_overflow_checks] fn add_assign(&mut self, other: $t) { *self += other } } - forward_ref_op_assign! { impl AddAssign, add_assign for $t, $t } + forward_ref_op_assign! { impl AddAssign, add_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } )+) } @@ -813,12 +846,14 @@ add_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f /// ``` #[lang = "sub_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "cannot subtract-assign `{Rhs}` from `{Self}`", label = "no implementation for `{Self} -= {Rhs}`" )] #[doc(alias = "-")] #[doc(alias = "-=")] +#[const_trait] pub trait SubAssign { /// Performs the `-=` operation. /// @@ -836,14 +871,18 @@ pub trait SubAssign { macro_rules! sub_assign_impl { ($($t:ty)+) => ($( #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl SubAssign for $t { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const SubAssign for $t { #[inline] #[track_caller] #[rustc_inherit_overflow_checks] fn sub_assign(&mut self, other: $t) { *self -= other } } - forward_ref_op_assign! { impl SubAssign, sub_assign for $t, $t } + forward_ref_op_assign! { impl SubAssign, sub_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } )+) } @@ -871,12 +910,14 @@ sub_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f /// ``` #[lang = "mul_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "cannot multiply-assign `{Self}` by `{Rhs}`", label = "no implementation for `{Self} *= {Rhs}`" )] #[doc(alias = "*")] #[doc(alias = "*=")] +#[const_trait] pub trait MulAssign { /// Performs the `*=` operation. /// @@ -894,14 +935,18 @@ pub trait MulAssign { macro_rules! mul_assign_impl { ($($t:ty)+) => ($( #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl MulAssign for $t { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const MulAssign for $t { #[inline] #[track_caller] #[rustc_inherit_overflow_checks] fn mul_assign(&mut self, other: $t) { *self *= other } } - forward_ref_op_assign! { impl MulAssign, mul_assign for $t, $t } + forward_ref_op_assign! { impl MulAssign, mul_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } )+) } @@ -929,12 +974,14 @@ mul_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f /// ``` #[lang = "div_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "cannot divide-assign `{Self}` by `{Rhs}`", label = "no implementation for `{Self} /= {Rhs}`" )] #[doc(alias = "/")] #[doc(alias = "/=")] +#[const_trait] pub trait DivAssign { /// Performs the `/=` operation. /// @@ -952,13 +999,17 @@ pub trait DivAssign { macro_rules! div_assign_impl { ($($t:ty)+) => ($( #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl DivAssign for $t { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const DivAssign for $t { #[inline] #[track_caller] fn div_assign(&mut self, other: $t) { *self /= other } } - forward_ref_op_assign! { impl DivAssign, div_assign for $t, $t } + forward_ref_op_assign! { impl DivAssign, div_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } )+) } @@ -990,12 +1041,14 @@ div_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f /// ``` #[lang = "rem_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "cannot calculate and assign the remainder of `{Self}` divided by `{Rhs}`", label = "no implementation for `{Self} %= {Rhs}`" )] #[doc(alias = "%")] #[doc(alias = "%=")] +#[const_trait] pub trait RemAssign { /// Performs the `%=` operation. /// @@ -1013,13 +1066,17 @@ pub trait RemAssign { macro_rules! rem_assign_impl { ($($t:ty)+) => ($( #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl RemAssign for $t { + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] + impl const RemAssign for $t { #[inline] #[track_caller] fn rem_assign(&mut self, other: $t) { *self %= other } } - forward_ref_op_assign! { impl RemAssign, rem_assign for $t, $t } + forward_ref_op_assign! { impl RemAssign, rem_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")], + const } )+) } diff --git a/library/core/src/ops/bit.rs b/library/core/src/ops/bit.rs index deb54c8ba348e..1a44243e0dc40 100644 --- a/library/core/src/ops/bit.rs +++ b/library/core/src/ops/bit.rs @@ -61,7 +61,8 @@ macro_rules! not_impl { fn not(self) -> $t { !self } } - forward_ref_unop! { impl Not, not for $t } + forward_ref_unop! { impl Not, not for $t, + #[stable(feature = "rust1", since = "1.0.0")] } )*) } @@ -171,7 +172,8 @@ macro_rules! bitand_impl { fn bitand(self, rhs: $t) -> $t { self & rhs } } - forward_ref_binop! { impl BitAnd, bitand for $t, $t } + forward_ref_binop! { impl BitAnd, bitand for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] } )*) } @@ -271,7 +273,8 @@ macro_rules! bitor_impl { fn bitor(self, rhs: $t) -> $t { self | rhs } } - forward_ref_binop! { impl BitOr, bitor for $t, $t } + forward_ref_binop! { impl BitOr, bitor for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] } )*) } @@ -371,7 +374,8 @@ macro_rules! bitxor_impl { fn bitxor(self, other: $t) -> $t { self ^ other } } - forward_ref_binop! { impl BitXor, bitxor for $t, $t } + forward_ref_binop! { impl BitXor, bitxor for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] } )*) } @@ -471,7 +475,8 @@ macro_rules! shl_impl { } } - forward_ref_binop! { impl Shl, shl for $t, $f } + forward_ref_binop! { impl Shl, shl for $t, $f, + #[stable(feature = "rust1", since = "1.0.0")] } }; } @@ -589,7 +594,8 @@ macro_rules! shr_impl { } } - forward_ref_binop! { impl Shr, shr for $t, $f } + forward_ref_binop! { impl Shr, shr for $t, $f, + #[stable(feature = "rust1", since = "1.0.0")] } }; } @@ -719,7 +725,8 @@ macro_rules! bitand_assign_impl { 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 BitAndAssign, bitand_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } )+) } @@ -790,7 +797,8 @@ macro_rules! bitor_assign_impl { 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 BitOrAssign, bitor_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } )+) } @@ -861,7 +869,8 @@ macro_rules! bitxor_assign_impl { 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 BitXorAssign, bitxor_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } )+) } @@ -925,7 +934,8 @@ macro_rules! shl_assign_impl { } } - forward_ref_op_assign! { impl ShlAssign, shl_assign for $t, $f } + forward_ref_op_assign! { impl ShlAssign, shl_assign for $t, $f, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } }; } @@ -1007,7 +1017,8 @@ macro_rules! shr_assign_impl { } } - forward_ref_op_assign! { impl ShrAssign, shr_assign for $t, $f } + forward_ref_op_assign! { impl ShrAssign, shr_assign for $t, $f, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] } }; } diff --git a/library/core/src/time.rs b/library/core/src/time.rs index 0fb5c0bac7562..559a860b85e19 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -1100,7 +1100,8 @@ impl Duration { } #[stable(feature = "duration", since = "1.3.0")] -impl Add for Duration { +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] +impl const Add for Duration { type Output = Duration; #[inline] @@ -1110,7 +1111,8 @@ impl Add for Duration { } #[stable(feature = "time_augmented_assignment", since = "1.9.0")] -impl AddAssign for Duration { +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] +impl const AddAssign for Duration { #[inline] fn add_assign(&mut self, rhs: Duration) { *self = *self + rhs; @@ -1118,7 +1120,8 @@ impl AddAssign for Duration { } #[stable(feature = "duration", since = "1.3.0")] -impl Sub for Duration { +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] +impl const Sub for Duration { type Output = Duration; #[inline] @@ -1128,7 +1131,8 @@ impl Sub for Duration { } #[stable(feature = "time_augmented_assignment", since = "1.9.0")] -impl SubAssign for Duration { +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] +impl const SubAssign for Duration { #[inline] fn sub_assign(&mut self, rhs: Duration) { *self = *self - rhs; @@ -1136,7 +1140,8 @@ impl SubAssign for Duration { } #[stable(feature = "duration", since = "1.3.0")] -impl Mul for Duration { +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] +impl const Mul for Duration { type Output = Duration; #[inline] @@ -1146,7 +1151,8 @@ impl Mul for Duration { } #[stable(feature = "symmetric_u32_duration_mul", since = "1.31.0")] -impl Mul for u32 { +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] +impl const Mul for u32 { type Output = Duration; #[inline] @@ -1156,7 +1162,8 @@ impl Mul for u32 { } #[stable(feature = "time_augmented_assignment", since = "1.9.0")] -impl MulAssign for Duration { +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] +impl const MulAssign for Duration { #[inline] fn mul_assign(&mut self, rhs: u32) { *self = *self * rhs; @@ -1164,7 +1171,8 @@ impl MulAssign for Duration { } #[stable(feature = "duration", since = "1.3.0")] -impl Div for Duration { +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] +impl const Div for Duration { type Output = Duration; #[inline] @@ -1175,7 +1183,8 @@ impl Div for Duration { } #[stable(feature = "time_augmented_assignment", since = "1.9.0")] -impl DivAssign for Duration { +#[rustc_const_unstable(feature = "const_arith_ops", issue = "143802")] +impl const DivAssign for Duration { #[inline] #[track_caller] fn div_assign(&mut self, rhs: u32) { diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs index e2249bd7f6a11..c4bf569a8f4fb 100644 --- a/library/coretests/tests/lib.rs +++ b/library/coretests/tests/lib.rs @@ -16,11 +16,11 @@ #![feature(cfg_target_has_reliable_f16_f128)] #![feature(char_max_len)] #![feature(clone_to_uninit)] +#![feature(const_arith_ops)] #![feature(const_deref)] #![feature(const_destruct)] #![feature(const_eval_select)] #![feature(const_float_round_methods)] -#![feature(const_ops)] #![feature(const_ref_cell)] #![feature(const_trait_impl)] #![feature(core_float_math)] diff --git a/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs b/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs index 9c6141d822263..7317c62df7fe8 100644 --- a/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs +++ b/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs @@ -1,6 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::Msrv; -use clippy_utils::qualify_min_const_fn::is_stable_const_fn; use clippy_utils::source::SpanRangeExt; use clippy_utils::ty::implements_trait; use clippy_utils::visitors::for_each_expr_without_closures; @@ -21,7 +20,7 @@ pub(super) fn check<'tcx>( expr: &'tcx hir::Expr<'_>, assignee: &'tcx hir::Expr<'_>, e: &'tcx hir::Expr<'_>, - msrv: Msrv, + _msrv: Msrv, ) { if let hir::ExprKind::Binary(op, l, r) = &e.kind { let lint = |assignee: &hir::Expr<'_>, rhs: &hir::Expr<'_>| { @@ -45,10 +44,8 @@ pub(super) fn check<'tcx>( } // Skip if the trait is not stable in const contexts - if is_in_const_context(cx) - && let Some(binop_id) = cx.tcx.associated_item_def_ids(trait_id).first() - && !is_stable_const_fn(cx, *binop_id, msrv) - { + // FIXME: reintroduce a better check after this is merged back into Clippy + if is_in_const_context(cx) { return; } diff --git a/src/tools/clippy/tests/ui/assign_ops.fixed b/src/tools/clippy/tests/ui/assign_ops.fixed index eee61f949e76b..60ad8379f62ee 100644 --- a/src/tools/clippy/tests/ui/assign_ops.fixed +++ b/src/tools/clippy/tests/ui/assign_ops.fixed @@ -1,6 +1,7 @@ #![allow(clippy::useless_vec)] #![warn(clippy::assign_op_pattern)] -#![feature(const_trait_impl, const_ops)] +#![feature(const_arith_ops)] +#![feature(const_trait_impl)] use core::num::Wrapping; use std::ops::{Mul, MulAssign}; diff --git a/src/tools/clippy/tests/ui/assign_ops.rs b/src/tools/clippy/tests/ui/assign_ops.rs index 13ffcee0a3c8a..d9a7f8c48accf 100644 --- a/src/tools/clippy/tests/ui/assign_ops.rs +++ b/src/tools/clippy/tests/ui/assign_ops.rs @@ -1,6 +1,7 @@ #![allow(clippy::useless_vec)] #![warn(clippy::assign_op_pattern)] -#![feature(const_trait_impl, const_ops)] +#![feature(const_arith_ops)] +#![feature(const_trait_impl)] use core::num::Wrapping; use std::ops::{Mul, MulAssign}; diff --git a/src/tools/clippy/tests/ui/assign_ops.stderr b/src/tools/clippy/tests/ui/assign_ops.stderr index c5e698b3ee118..3d0465539eb82 100644 --- a/src/tools/clippy/tests/ui/assign_ops.stderr +++ b/src/tools/clippy/tests/ui/assign_ops.stderr @@ -1,5 +1,5 @@ error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:10:5 + --> tests/ui/assign_ops.rs:11:5 | LL | a = a + 1; | ^^^^^^^^^ help: replace it with: `a += 1` @@ -8,67 +8,67 @@ LL | a = a + 1; = help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:12:5 + --> tests/ui/assign_ops.rs:13:5 | LL | a = 1 + a; | ^^^^^^^^^ help: replace it with: `a += 1` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:14:5 + --> tests/ui/assign_ops.rs:15:5 | LL | a = a - 1; | ^^^^^^^^^ help: replace it with: `a -= 1` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:16:5 + --> tests/ui/assign_ops.rs:17:5 | LL | a = a * 99; | ^^^^^^^^^^ help: replace it with: `a *= 99` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:18:5 + --> tests/ui/assign_ops.rs:19:5 | LL | a = 42 * a; | ^^^^^^^^^^ help: replace it with: `a *= 42` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:20:5 + --> tests/ui/assign_ops.rs:21:5 | LL | a = a / 2; | ^^^^^^^^^ help: replace it with: `a /= 2` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:22:5 + --> tests/ui/assign_ops.rs:23:5 | LL | a = a % 5; | ^^^^^^^^^ help: replace it with: `a %= 5` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:24:5 + --> tests/ui/assign_ops.rs:25:5 | LL | a = a & 1; | ^^^^^^^^^ help: replace it with: `a &= 1` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:31:5 + --> tests/ui/assign_ops.rs:32:5 | LL | s = s + "bla"; | ^^^^^^^^^^^^^ help: replace it with: `s += "bla"` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:36:5 + --> tests/ui/assign_ops.rs:37:5 | LL | a = a + Wrapping(1u32); | ^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a += Wrapping(1u32)` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:39:5 + --> tests/ui/assign_ops.rs:40:5 | LL | v[0] = v[0] + v[1]; | ^^^^^^^^^^^^^^^^^^ help: replace it with: `v[0] += v[1]` error: manual implementation of an assign operation - --> tests/ui/assign_ops.rs:52:5 + --> tests/ui/assign_ops.rs:53:5 | LL | buf = buf + cows.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()` diff --git a/tests/ui/traits/const-traits/call-const-trait-method-pass.rs b/tests/ui/traits/const-traits/call-const-trait-method-pass.rs index 2d9c2ca086178..1d24f2ce00c12 100644 --- a/tests/ui/traits/const-traits/call-const-trait-method-pass.rs +++ b/tests/ui/traits/const-traits/call-const-trait-method-pass.rs @@ -1,4 +1,6 @@ -#![feature(const_trait_impl, const_ops, const_cmp)] +#![feature(const_arith_ops)] +#![feature(const_cmp)] +#![feature(const_trait_impl)] //@ check-pass struct Int(i32); diff --git a/tests/ui/traits/const-traits/const-and-non-const-impl.rs b/tests/ui/traits/const-traits/const-and-non-const-impl.rs index 85e2c5d3df62a..d824cfd3c6341 100644 --- a/tests/ui/traits/const-traits/const-and-non-const-impl.rs +++ b/tests/ui/traits/const-traits/const-and-non-const-impl.rs @@ -1,6 +1,7 @@ //@ known-bug: #110395 -#![feature(const_trait_impl, const_ops)] +#![feature(const_arith_ops)] +#![feature(const_trait_impl)] pub struct Int(i32); diff --git a/tests/ui/traits/const-traits/const-and-non-const-impl.stderr b/tests/ui/traits/const-traits/const-and-non-const-impl.stderr index 4eb1517734700..d765e288e0a50 100644 --- a/tests/ui/traits/const-traits/const-and-non-const-impl.stderr +++ b/tests/ui/traits/const-traits/const-and-non-const-impl.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Add` for type `Int` - --> $DIR/const-and-non-const-impl.rs:23:1 + --> $DIR/const-and-non-const-impl.rs:24:1 | LL | impl std::ops::Add for Int { | -------------------------- first implementation here @@ -8,7 +8,7 @@ LL | impl const std::ops::Add for Int { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Int` error[E0117]: only traits defined in the current crate can be implemented for primitive types - --> $DIR/const-and-non-const-impl.rs:7:1 + --> $DIR/const-and-non-const-impl.rs:8:1 | LL | impl const std::ops::Add for i32 { | ^^^^^^^^^^^-------------^^^^^--- diff --git a/tests/ui/traits/const-traits/generic-bound.rs b/tests/ui/traits/const-traits/generic-bound.rs index 99de21471b20c..a8df00814183f 100644 --- a/tests/ui/traits/const-traits/generic-bound.rs +++ b/tests/ui/traits/const-traits/generic-bound.rs @@ -1,6 +1,7 @@ //@ check-pass -#![feature(const_trait_impl, const_ops)] +#![feature(const_arith_ops)] +#![feature(const_trait_impl)] use std::marker::PhantomData;