Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 90eb42d

Browse files
committedOct 20, 2021
Added const versions of common numeric operations
1 parent 42983a2 commit 90eb42d

File tree

6 files changed

+232
-106
lines changed

6 files changed

+232
-106
lines changed
 

‎library/core/src/internal_macros.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ macro_rules! forward_ref_unop {
55
forward_ref_unop!(impl $imp, $method for $t,
66
#[stable(feature = "rust1", since = "1.0.0")]);
77
};
8+
(impl const $imp:ident, $method:ident for $t:ty) => {
9+
forward_ref_unop!(impl const $imp, $method for $t,
10+
#[stable(feature = "rust1", since = "1.0.0")]);
11+
};
12+
(impl const $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
13+
#[$attr]
14+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
15+
impl const $imp for &$t {
16+
type Output = <$t as $imp>::Output;
17+
18+
#[inline]
19+
fn $method(self) -> <$t as $imp>::Output {
20+
$imp::$method(*self)
21+
}
22+
}
23+
};
824
(impl $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
925
#[$attr]
1026
impl $imp for &$t {
@@ -25,6 +41,44 @@ macro_rules! forward_ref_binop {
2541
forward_ref_binop!(impl $imp, $method for $t, $u,
2642
#[stable(feature = "rust1", since = "1.0.0")]);
2743
};
44+
(impl const $imp:ident, $method:ident for $t:ty, $u:ty) => {
45+
forward_ref_binop!(impl const $imp, $method for $t, $u,
46+
#[stable(feature = "rust1", since = "1.0.0")]);
47+
};
48+
(impl const $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
49+
#[$attr]
50+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
51+
impl<'a> const $imp<$u> for &'a $t {
52+
type Output = <$t as $imp<$u>>::Output;
53+
54+
#[inline]
55+
fn $method(self, other: $u) -> <$t as $imp<$u>>::Output {
56+
$imp::$method(*self, other)
57+
}
58+
}
59+
60+
#[$attr]
61+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
62+
impl const $imp<&$u> for $t {
63+
type Output = <$t as $imp<$u>>::Output;
64+
65+
#[inline]
66+
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
67+
$imp::$method(self, *other)
68+
}
69+
}
70+
71+
#[$attr]
72+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
73+
impl const $imp<&$u> for &$t {
74+
type Output = <$t as $imp<$u>>::Output;
75+
76+
#[inline]
77+
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
78+
$imp::$method(*self, *other)
79+
}
80+
}
81+
};
2882
(impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
2983
#[$attr]
3084
impl<'a> $imp<$u> for &'a $t {
@@ -65,6 +119,20 @@ macro_rules! forward_ref_op_assign {
65119
forward_ref_op_assign!(impl $imp, $method for $t, $u,
66120
#[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
67121
};
122+
(impl const $imp:ident, $method:ident for $t:ty, $u:ty) => {
123+
forward_ref_op_assign!(impl const $imp, $method for $t, $u,
124+
#[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
125+
};
126+
(impl const $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
127+
#[$attr]
128+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
129+
impl const $imp<&$u> for $t {
130+
#[inline]
131+
fn $method(&mut self, other: &$u) {
132+
$imp::$method(self, *other);
133+
}
134+
}
135+
};
68136
(impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
69137
#[$attr]
70138
impl $imp<&$u> for $t {

‎library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
#![feature(const_likely)]
116116
#![feature(const_maybe_uninit_as_ptr)]
117117
#![feature(const_maybe_uninit_assume_init)]
118+
#![feature(const_ops)]
118119
#![feature(const_option)]
119120
#![feature(const_pin)]
120121
#![feature(const_replace)]

‎library/core/src/num/nonzero.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ macro_rules! nonzero_integers {
9292
}
9393

9494
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
95-
impl BitOr for $Ty {
95+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
96+
impl const BitOr for $Ty {
9697
type Output = Self;
9798
#[inline]
9899
fn bitor(self, rhs: Self) -> Self::Output {
@@ -103,7 +104,8 @@ macro_rules! nonzero_integers {
103104
}
104105

105106
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
106-
impl BitOr<$Int> for $Ty {
107+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
108+
impl const BitOr<$Int> for $Ty {
107109
type Output = Self;
108110
#[inline]
109111
fn bitor(self, rhs: $Int) -> Self::Output {
@@ -115,7 +117,8 @@ macro_rules! nonzero_integers {
115117
}
116118

117119
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
118-
impl BitOr<$Ty> for $Int {
120+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
121+
impl const BitOr<$Ty> for $Int {
119122
type Output = $Ty;
120123
#[inline]
121124
fn bitor(self, rhs: $Ty) -> Self::Output {
@@ -127,15 +130,17 @@ macro_rules! nonzero_integers {
127130
}
128131

129132
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
130-
impl BitOrAssign for $Ty {
133+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
134+
impl const BitOrAssign for $Ty {
131135
#[inline]
132136
fn bitor_assign(&mut self, rhs: Self) {
133137
*self = *self | rhs;
134138
}
135139
}
136140

137141
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
138-
impl BitOrAssign<$Int> for $Ty {
142+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
143+
impl const BitOrAssign<$Int> for $Ty {
139144
#[inline]
140145
fn bitor_assign(&mut self, rhs: $Int) {
141146
*self = *self | rhs;
@@ -257,7 +262,8 @@ macro_rules! nonzero_integers_div {
257262
( $( $Ty: ident($Int: ty); )+ ) => {
258263
$(
259264
#[stable(feature = "nonzero_div", since = "1.51.0")]
260-
impl Div<$Ty> for $Int {
265+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
266+
impl const Div<$Ty> for $Int {
261267
type Output = $Int;
262268
/// This operation rounds towards zero,
263269
/// truncating any fractional part of the exact result, and cannot panic.
@@ -270,7 +276,8 @@ macro_rules! nonzero_integers_div {
270276
}
271277

272278
#[stable(feature = "nonzero_div", since = "1.51.0")]
273-
impl Rem<$Ty> for $Int {
279+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
280+
impl const Rem<$Ty> for $Int {
274281
type Output = $Int;
275282
/// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
276283
#[inline]

‎library/core/src/num/wrapping.rs

Lines changed: 77 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Wrapping<T> {
8787
macro_rules! sh_impl_signed {
8888
($t:ident, $f:ident) => {
8989
#[stable(feature = "rust1", since = "1.0.0")]
90-
impl Shl<$f> for Wrapping<$t> {
90+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
91+
impl const Shl<$f> for Wrapping<$t> {
9192
type Output = Wrapping<$t>;
9293

9394
#[inline]
@@ -99,20 +100,22 @@ macro_rules! sh_impl_signed {
99100
}
100101
}
101102
}
102-
forward_ref_binop! { impl Shl, shl for Wrapping<$t>, $f,
103+
forward_ref_binop! { impl const Shl, shl for Wrapping<$t>, $f,
103104
#[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
104105

105106
#[stable(feature = "op_assign_traits", since = "1.8.0")]
106-
impl ShlAssign<$f> for Wrapping<$t> {
107+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
108+
impl const ShlAssign<$f> for Wrapping<$t> {
107109
#[inline]
108110
fn shl_assign(&mut self, other: $f) {
109111
*self = *self << other;
110112
}
111113
}
112-
forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f }
114+
forward_ref_op_assign! { impl const ShlAssign, shl_assign for Wrapping<$t>, $f }
113115

114116
#[stable(feature = "rust1", since = "1.0.0")]
115-
impl Shr<$f> for Wrapping<$t> {
117+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
118+
impl const Shr<$f> for Wrapping<$t> {
116119
type Output = Wrapping<$t>;
117120

118121
#[inline]
@@ -124,63 +127,68 @@ macro_rules! sh_impl_signed {
124127
}
125128
}
126129
}
127-
forward_ref_binop! { impl Shr, shr for Wrapping<$t>, $f,
130+
forward_ref_binop! { impl const Shr, shr for Wrapping<$t>, $f,
128131
#[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
129132

130133
#[stable(feature = "op_assign_traits", since = "1.8.0")]
131-
impl ShrAssign<$f> for Wrapping<$t> {
134+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
135+
impl const ShrAssign<$f> for Wrapping<$t> {
132136
#[inline]
133137
fn shr_assign(&mut self, other: $f) {
134138
*self = *self >> other;
135139
}
136140
}
137-
forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f }
141+
forward_ref_op_assign! { impl const ShrAssign, shr_assign for Wrapping<$t>, $f }
138142
};
139143
}
140144

141145
macro_rules! sh_impl_unsigned {
142146
($t:ident, $f:ident) => {
143147
#[stable(feature = "rust1", since = "1.0.0")]
144-
impl Shl<$f> for Wrapping<$t> {
148+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
149+
impl const Shl<$f> for Wrapping<$t> {
145150
type Output = Wrapping<$t>;
146151

147152
#[inline]
148153
fn shl(self, other: $f) -> Wrapping<$t> {
149154
Wrapping(self.0.wrapping_shl((other & self::shift_max::$t as $f) as u32))
150155
}
151156
}
152-
forward_ref_binop! { impl Shl, shl for Wrapping<$t>, $f,
157+
forward_ref_binop! { impl const Shl, shl for Wrapping<$t>, $f,
153158
#[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
154159

155160
#[stable(feature = "op_assign_traits", since = "1.8.0")]
156-
impl ShlAssign<$f> for Wrapping<$t> {
161+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
162+
impl const ShlAssign<$f> for Wrapping<$t> {
157163
#[inline]
158164
fn shl_assign(&mut self, other: $f) {
159165
*self = *self << other;
160166
}
161167
}
162-
forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f }
168+
forward_ref_op_assign! { impl const ShlAssign, shl_assign for Wrapping<$t>, $f }
163169

164170
#[stable(feature = "rust1", since = "1.0.0")]
165-
impl Shr<$f> for Wrapping<$t> {
171+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
172+
impl const Shr<$f> for Wrapping<$t> {
166173
type Output = Wrapping<$t>;
167174

168175
#[inline]
169176
fn shr(self, other: $f) -> Wrapping<$t> {
170177
Wrapping(self.0.wrapping_shr((other & self::shift_max::$t as $f) as u32))
171178
}
172179
}
173-
forward_ref_binop! { impl Shr, shr for Wrapping<$t>, $f,
180+
forward_ref_binop! { impl const Shr, shr for Wrapping<$t>, $f,
174181
#[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
175182

176183
#[stable(feature = "op_assign_traits", since = "1.8.0")]
177-
impl ShrAssign<$f> for Wrapping<$t> {
184+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
185+
impl const ShrAssign<$f> for Wrapping<$t> {
178186
#[inline]
179187
fn shr_assign(&mut self, other: $f) {
180188
*self = *self >> other;
181189
}
182190
}
183-
forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f }
191+
forward_ref_op_assign! { impl const ShrAssign, shr_assign for Wrapping<$t>, $f }
184192
};
185193
}
186194

@@ -209,49 +217,54 @@ sh_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
209217
macro_rules! wrapping_impl {
210218
($($t:ty)*) => ($(
211219
#[stable(feature = "rust1", since = "1.0.0")]
212-
impl Add for Wrapping<$t> {
220+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
221+
impl const Add for Wrapping<$t> {
213222
type Output = Wrapping<$t>;
214223

215224
#[inline]
216225
fn add(self, other: Wrapping<$t>) -> Wrapping<$t> {
217226
Wrapping(self.0.wrapping_add(other.0))
218227
}
219228
}
220-
forward_ref_binop! { impl Add, add for Wrapping<$t>, Wrapping<$t>,
229+
forward_ref_binop! { impl const Add, add for Wrapping<$t>, Wrapping<$t>,
221230
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
222231

223232
#[stable(feature = "op_assign_traits", since = "1.8.0")]
224-
impl AddAssign for Wrapping<$t> {
233+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
234+
impl const AddAssign for Wrapping<$t> {
225235
#[inline]
226236
fn add_assign(&mut self, other: Wrapping<$t>) {
227237
*self = *self + other;
228238
}
229239
}
230-
forward_ref_op_assign! { impl AddAssign, add_assign for Wrapping<$t>, Wrapping<$t> }
240+
forward_ref_op_assign! { impl const AddAssign, add_assign for Wrapping<$t>, Wrapping<$t> }
231241

232242
#[stable(feature = "rust1", since = "1.0.0")]
233-
impl Sub for Wrapping<$t> {
243+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
244+
impl const Sub for Wrapping<$t> {
234245
type Output = Wrapping<$t>;
235246

236247
#[inline]
237248
fn sub(self, other: Wrapping<$t>) -> Wrapping<$t> {
238249
Wrapping(self.0.wrapping_sub(other.0))
239250
}
240251
}
241-
forward_ref_binop! { impl Sub, sub for Wrapping<$t>, Wrapping<$t>,
252+
forward_ref_binop! { impl const Sub, sub for Wrapping<$t>, Wrapping<$t>,
242253
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
243254

244255
#[stable(feature = "op_assign_traits", since = "1.8.0")]
245-
impl SubAssign for Wrapping<$t> {
256+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
257+
impl const SubAssign for Wrapping<$t> {
246258
#[inline]
247259
fn sub_assign(&mut self, other: Wrapping<$t>) {
248260
*self = *self - other;
249261
}
250262
}
251-
forward_ref_op_assign! { impl SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t> }
263+
forward_ref_op_assign! { impl const SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t> }
252264

253265
#[stable(feature = "rust1", since = "1.0.0")]
254-
impl Mul for Wrapping<$t> {
266+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
267+
impl const Mul for Wrapping<$t> {
255268
type Output = Wrapping<$t>;
256269

257270
#[inline]
@@ -263,140 +276,153 @@ macro_rules! wrapping_impl {
263276
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
264277

265278
#[stable(feature = "op_assign_traits", since = "1.8.0")]
266-
impl MulAssign for Wrapping<$t> {
279+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
280+
impl const MulAssign for Wrapping<$t> {
267281
#[inline]
268282
fn mul_assign(&mut self, other: Wrapping<$t>) {
269283
*self = *self * other;
270284
}
271285
}
272-
forward_ref_op_assign! { impl MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t> }
286+
forward_ref_op_assign! { impl const MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t> }
273287

274288
#[stable(feature = "wrapping_div", since = "1.3.0")]
275-
impl Div for Wrapping<$t> {
289+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
290+
impl const Div for Wrapping<$t> {
276291
type Output = Wrapping<$t>;
277292

278293
#[inline]
279294
fn div(self, other: Wrapping<$t>) -> Wrapping<$t> {
280295
Wrapping(self.0.wrapping_div(other.0))
281296
}
282297
}
283-
forward_ref_binop! { impl Div, div for Wrapping<$t>, Wrapping<$t>,
298+
forward_ref_binop! { impl const Div, div for Wrapping<$t>, Wrapping<$t>,
284299
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
285300

286301
#[stable(feature = "op_assign_traits", since = "1.8.0")]
287-
impl DivAssign for Wrapping<$t> {
302+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
303+
impl const DivAssign for Wrapping<$t> {
288304
#[inline]
289305
fn div_assign(&mut self, other: Wrapping<$t>) {
290306
*self = *self / other;
291307
}
292308
}
293-
forward_ref_op_assign! { impl DivAssign, div_assign for Wrapping<$t>, Wrapping<$t> }
309+
forward_ref_op_assign! { impl const DivAssign, div_assign for Wrapping<$t>, Wrapping<$t> }
294310

295311
#[stable(feature = "wrapping_impls", since = "1.7.0")]
296-
impl Rem for Wrapping<$t> {
312+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
313+
impl const Rem for Wrapping<$t> {
297314
type Output = Wrapping<$t>;
298315

299316
#[inline]
300317
fn rem(self, other: Wrapping<$t>) -> Wrapping<$t> {
301318
Wrapping(self.0.wrapping_rem(other.0))
302319
}
303320
}
304-
forward_ref_binop! { impl Rem, rem for Wrapping<$t>, Wrapping<$t>,
321+
forward_ref_binop! { impl const Rem, rem for Wrapping<$t>, Wrapping<$t>,
305322
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
306323

307324
#[stable(feature = "op_assign_traits", since = "1.8.0")]
308-
impl RemAssign for Wrapping<$t> {
325+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
326+
impl const RemAssign for Wrapping<$t> {
309327
#[inline]
310328
fn rem_assign(&mut self, other: Wrapping<$t>) {
311329
*self = *self % other;
312330
}
313331
}
314-
forward_ref_op_assign! { impl RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t> }
332+
forward_ref_op_assign! { impl const RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t> }
315333

316334
#[stable(feature = "rust1", since = "1.0.0")]
317-
impl Not for Wrapping<$t> {
335+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
336+
impl const Not for Wrapping<$t> {
318337
type Output = Wrapping<$t>;
319338

320339
#[inline]
321340
fn not(self) -> Wrapping<$t> {
322341
Wrapping(!self.0)
323342
}
324343
}
325-
forward_ref_unop! { impl Not, not for Wrapping<$t>,
344+
forward_ref_unop! { impl const Not, not for Wrapping<$t>,
326345
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
327346

328347
#[stable(feature = "rust1", since = "1.0.0")]
329-
impl BitXor for Wrapping<$t> {
348+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
349+
impl const BitXor for Wrapping<$t> {
330350
type Output = Wrapping<$t>;
331351

332352
#[inline]
333353
fn bitxor(self, other: Wrapping<$t>) -> Wrapping<$t> {
334354
Wrapping(self.0 ^ other.0)
335355
}
336356
}
337-
forward_ref_binop! { impl BitXor, bitxor for Wrapping<$t>, Wrapping<$t>,
357+
forward_ref_binop! { impl const BitXor, bitxor for Wrapping<$t>, Wrapping<$t>,
338358
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
339359

340360
#[stable(feature = "op_assign_traits", since = "1.8.0")]
341-
impl BitXorAssign for Wrapping<$t> {
361+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
362+
impl const BitXorAssign for Wrapping<$t> {
342363
#[inline]
343364
fn bitxor_assign(&mut self, other: Wrapping<$t>) {
344365
*self = *self ^ other;
345366
}
346367
}
347-
forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t> }
368+
forward_ref_op_assign! { impl const BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t> }
348369

349370
#[stable(feature = "rust1", since = "1.0.0")]
350-
impl BitOr for Wrapping<$t> {
371+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
372+
impl const BitOr for Wrapping<$t> {
351373
type Output = Wrapping<$t>;
352374

353375
#[inline]
354376
fn bitor(self, other: Wrapping<$t>) -> Wrapping<$t> {
355377
Wrapping(self.0 | other.0)
356378
}
357379
}
358-
forward_ref_binop! { impl BitOr, bitor for Wrapping<$t>, Wrapping<$t>,
380+
forward_ref_binop! { impl const BitOr, bitor for Wrapping<$t>, Wrapping<$t>,
359381
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
360382

361383
#[stable(feature = "op_assign_traits", since = "1.8.0")]
362-
impl BitOrAssign for Wrapping<$t> {
384+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
385+
impl const BitOrAssign for Wrapping<$t> {
363386
#[inline]
364387
fn bitor_assign(&mut self, other: Wrapping<$t>) {
365388
*self = *self | other;
366389
}
367390
}
368-
forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t> }
391+
forward_ref_op_assign! { impl const BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t> }
369392

370393
#[stable(feature = "rust1", since = "1.0.0")]
371-
impl BitAnd for Wrapping<$t> {
394+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
395+
impl const BitAnd for Wrapping<$t> {
372396
type Output = Wrapping<$t>;
373397

374398
#[inline]
375399
fn bitand(self, other: Wrapping<$t>) -> Wrapping<$t> {
376400
Wrapping(self.0 & other.0)
377401
}
378402
}
379-
forward_ref_binop! { impl BitAnd, bitand for Wrapping<$t>, Wrapping<$t>,
403+
forward_ref_binop! { impl const BitAnd, bitand for Wrapping<$t>, Wrapping<$t>,
380404
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
381405

382406
#[stable(feature = "op_assign_traits", since = "1.8.0")]
383-
impl BitAndAssign for Wrapping<$t> {
407+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
408+
impl const BitAndAssign for Wrapping<$t> {
384409
#[inline]
385410
fn bitand_assign(&mut self, other: Wrapping<$t>) {
386411
*self = *self & other;
387412
}
388413
}
389-
forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t> }
414+
forward_ref_op_assign! { impl const BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t> }
390415

391416
#[stable(feature = "wrapping_neg", since = "1.10.0")]
392-
impl Neg for Wrapping<$t> {
417+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
418+
impl const Neg for Wrapping<$t> {
393419
type Output = Self;
394420
#[inline]
395421
fn neg(self) -> Self {
396422
Wrapping(0) - self
397423
}
398424
}
399-
forward_ref_unop! { impl Neg, neg for Wrapping<$t>,
425+
forward_ref_unop! { impl const Neg, neg for Wrapping<$t>,
400426
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
401427

402428
)*)

‎library/core/src/ops/arith.rs

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,16 @@ pub trait Add<Rhs = Self> {
9292
macro_rules! add_impl {
9393
($($t:ty)*) => ($(
9494
#[stable(feature = "rust1", since = "1.0.0")]
95-
impl Add for $t {
95+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
96+
impl const Add for $t {
9697
type Output = $t;
9798

9899
#[inline]
99100
#[rustc_inherit_overflow_checks]
100101
fn add(self, other: $t) -> $t { self + other }
101102
}
102103

103-
forward_ref_binop! { impl Add, add for $t, $t }
104+
forward_ref_binop! { impl const Add, add for $t, $t }
104105
)*)
105106
}
106107

@@ -198,15 +199,16 @@ pub trait Sub<Rhs = Self> {
198199
macro_rules! sub_impl {
199200
($($t:ty)*) => ($(
200201
#[stable(feature = "rust1", since = "1.0.0")]
201-
impl Sub for $t {
202+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
203+
impl const Sub for $t {
202204
type Output = $t;
203205

204206
#[inline]
205207
#[rustc_inherit_overflow_checks]
206208
fn sub(self, other: $t) -> $t { self - other }
207209
}
208210

209-
forward_ref_binop! { impl Sub, sub for $t, $t }
211+
forward_ref_binop! { impl const Sub, sub for $t, $t }
210212
)*)
211213
}
212214

@@ -326,15 +328,16 @@ pub trait Mul<Rhs = Self> {
326328
macro_rules! mul_impl {
327329
($($t:ty)*) => ($(
328330
#[stable(feature = "rust1", since = "1.0.0")]
329-
impl Mul for $t {
331+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
332+
impl const Mul for $t {
330333
type Output = $t;
331334

332335
#[inline]
333336
#[rustc_inherit_overflow_checks]
334337
fn mul(self, other: $t) -> $t { self * other }
335338
}
336339

337-
forward_ref_binop! { impl Mul, mul for $t, $t }
340+
forward_ref_binop! { impl const Mul, mul for $t, $t }
338341
)*)
339342
}
340343

@@ -464,14 +467,15 @@ macro_rules! div_impl_integer {
464467
///
465468
#[doc = $panic]
466469
#[stable(feature = "rust1", since = "1.0.0")]
467-
impl Div for $t {
470+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
471+
impl const Div for $t {
468472
type Output = $t;
469473

470474
#[inline]
471475
fn div(self, other: $t) -> $t { self / other }
472476
}
473477

474-
forward_ref_binop! { impl Div, div for $t, $t }
478+
forward_ref_binop! { impl const Div, div for $t, $t }
475479
)*)*)
476480
}
477481

@@ -483,14 +487,15 @@ div_impl_integer! {
483487
macro_rules! div_impl_float {
484488
($($t:ty)*) => ($(
485489
#[stable(feature = "rust1", since = "1.0.0")]
486-
impl Div for $t {
490+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
491+
impl const Div for $t {
487492
type Output = $t;
488493

489494
#[inline]
490495
fn div(self, other: $t) -> $t { self / other }
491496
}
492497

493-
forward_ref_binop! { impl Div, div for $t, $t }
498+
forward_ref_binop! { impl const Div, div for $t, $t }
494499
)*)
495500
}
496501

@@ -564,14 +569,15 @@ macro_rules! rem_impl_integer {
564569
///
565570
#[doc = $panic]
566571
#[stable(feature = "rust1", since = "1.0.0")]
567-
impl Rem for $t {
572+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
573+
impl const Rem for $t {
568574
type Output = $t;
569575

570576
#[inline]
571577
fn rem(self, other: $t) -> $t { self % other }
572578
}
573579

574-
forward_ref_binop! { impl Rem, rem for $t, $t }
580+
forward_ref_binop! { impl const Rem, rem for $t, $t }
575581
)*)*)
576582
}
577583

@@ -598,14 +604,15 @@ macro_rules! rem_impl_float {
598604
/// assert_eq!(x % y, remainder);
599605
/// ```
600606
#[stable(feature = "rust1", since = "1.0.0")]
601-
impl Rem for $t {
607+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
608+
impl const Rem for $t {
602609
type Output = $t;
603610

604611
#[inline]
605612
fn rem(self, other: $t) -> $t { self % other }
606613
}
607614

608-
forward_ref_binop! { impl Rem, rem for $t, $t }
615+
forward_ref_binop! { impl const Rem, rem for $t, $t }
609616
)*)
610617
}
611618

@@ -671,15 +678,16 @@ pub trait Neg {
671678
macro_rules! neg_impl {
672679
($($t:ty)*) => ($(
673680
#[stable(feature = "rust1", since = "1.0.0")]
674-
impl Neg for $t {
681+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
682+
impl const Neg for $t {
675683
type Output = $t;
676684

677685
#[inline]
678686
#[rustc_inherit_overflow_checks]
679687
fn neg(self) -> $t { -self }
680688
}
681689

682-
forward_ref_unop! { impl Neg, neg for $t }
690+
forward_ref_unop! { impl const Neg, neg for $t }
683691
)*)
684692
}
685693

@@ -739,13 +747,14 @@ pub trait AddAssign<Rhs = Self> {
739747
macro_rules! add_assign_impl {
740748
($($t:ty)+) => ($(
741749
#[stable(feature = "op_assign_traits", since = "1.8.0")]
742-
impl AddAssign for $t {
750+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
751+
impl const AddAssign for $t {
743752
#[inline]
744753
#[rustc_inherit_overflow_checks]
745754
fn add_assign(&mut self, other: $t) { *self += other }
746755
}
747756

748-
forward_ref_op_assign! { impl AddAssign, add_assign for $t, $t }
757+
forward_ref_op_assign! { impl const AddAssign, add_assign for $t, $t }
749758
)+)
750759
}
751760

@@ -805,13 +814,14 @@ pub trait SubAssign<Rhs = Self> {
805814
macro_rules! sub_assign_impl {
806815
($($t:ty)+) => ($(
807816
#[stable(feature = "op_assign_traits", since = "1.8.0")]
808-
impl SubAssign for $t {
817+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
818+
impl const SubAssign for $t {
809819
#[inline]
810820
#[rustc_inherit_overflow_checks]
811821
fn sub_assign(&mut self, other: $t) { *self -= other }
812822
}
813823

814-
forward_ref_op_assign! { impl SubAssign, sub_assign for $t, $t }
824+
forward_ref_op_assign! { impl const SubAssign, sub_assign for $t, $t }
815825
)+)
816826
}
817827

@@ -862,13 +872,14 @@ pub trait MulAssign<Rhs = Self> {
862872
macro_rules! mul_assign_impl {
863873
($($t:ty)+) => ($(
864874
#[stable(feature = "op_assign_traits", since = "1.8.0")]
865-
impl MulAssign for $t {
875+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
876+
impl const MulAssign for $t {
866877
#[inline]
867878
#[rustc_inherit_overflow_checks]
868879
fn mul_assign(&mut self, other: $t) { *self *= other }
869880
}
870881

871-
forward_ref_op_assign! { impl MulAssign, mul_assign for $t, $t }
882+
forward_ref_op_assign! { impl const MulAssign, mul_assign for $t, $t }
872883
)+)
873884
}
874885

@@ -919,12 +930,13 @@ pub trait DivAssign<Rhs = Self> {
919930
macro_rules! div_assign_impl {
920931
($($t:ty)+) => ($(
921932
#[stable(feature = "op_assign_traits", since = "1.8.0")]
922-
impl DivAssign for $t {
933+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
934+
impl const DivAssign for $t {
923935
#[inline]
924936
fn div_assign(&mut self, other: $t) { *self /= other }
925937
}
926938

927-
forward_ref_op_assign! { impl DivAssign, div_assign for $t, $t }
939+
forward_ref_op_assign! { impl const DivAssign, div_assign for $t, $t }
928940
)+)
929941
}
930942

@@ -979,12 +991,13 @@ pub trait RemAssign<Rhs = Self> {
979991
macro_rules! rem_assign_impl {
980992
($($t:ty)+) => ($(
981993
#[stable(feature = "op_assign_traits", since = "1.8.0")]
982-
impl RemAssign for $t {
994+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
995+
impl const RemAssign for $t {
983996
#[inline]
984997
fn rem_assign(&mut self, other: $t) { *self %= other }
985998
}
986999

987-
forward_ref_op_assign! { impl RemAssign, rem_assign for $t, $t }
1000+
forward_ref_op_assign! { impl const RemAssign, rem_assign for $t, $t }
9881001
)+)
9891002
}
9901003

‎library/core/src/ops/bit.rs

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ pub trait Not {
5454
macro_rules! not_impl {
5555
($($t:ty)*) => ($(
5656
#[stable(feature = "rust1", since = "1.0.0")]
57-
impl Not for $t {
57+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
58+
impl const Not for $t {
5859
type Output = $t;
5960

6061
#[inline]
6162
fn not(self) -> $t { !self }
6263
}
6364

64-
forward_ref_unop! { impl Not, not for $t }
65+
forward_ref_unop! { impl const Not, not for $t }
6566
)*)
6667
}
6768

@@ -154,14 +155,15 @@ pub trait BitAnd<Rhs = Self> {
154155
macro_rules! bitand_impl {
155156
($($t:ty)*) => ($(
156157
#[stable(feature = "rust1", since = "1.0.0")]
157-
impl BitAnd for $t {
158+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
159+
impl const BitAnd for $t {
158160
type Output = $t;
159161

160162
#[inline]
161163
fn bitand(self, rhs: $t) -> $t { self & rhs }
162164
}
163165

164-
forward_ref_binop! { impl BitAnd, bitand for $t, $t }
166+
forward_ref_binop! { impl const BitAnd, bitand for $t, $t }
165167
)*)
166168
}
167169

@@ -254,14 +256,15 @@ pub trait BitOr<Rhs = Self> {
254256
macro_rules! bitor_impl {
255257
($($t:ty)*) => ($(
256258
#[stable(feature = "rust1", since = "1.0.0")]
257-
impl BitOr for $t {
259+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
260+
impl const BitOr for $t {
258261
type Output = $t;
259262

260263
#[inline]
261264
fn bitor(self, rhs: $t) -> $t { self | rhs }
262265
}
263266

264-
forward_ref_binop! { impl BitOr, bitor for $t, $t }
267+
forward_ref_binop! { impl const BitOr, bitor for $t, $t }
265268
)*)
266269
}
267270

@@ -354,14 +357,15 @@ pub trait BitXor<Rhs = Self> {
354357
macro_rules! bitxor_impl {
355358
($($t:ty)*) => ($(
356359
#[stable(feature = "rust1", since = "1.0.0")]
357-
impl BitXor for $t {
360+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
361+
impl const BitXor for $t {
358362
type Output = $t;
359363

360364
#[inline]
361365
fn bitxor(self, other: $t) -> $t { self ^ other }
362366
}
363367

364-
forward_ref_binop! { impl BitXor, bitxor for $t, $t }
368+
forward_ref_binop! { impl const BitXor, bitxor for $t, $t }
365369
)*)
366370
}
367371

@@ -451,7 +455,8 @@ pub trait Shl<Rhs = Self> {
451455
macro_rules! shl_impl {
452456
($t:ty, $f:ty) => {
453457
#[stable(feature = "rust1", since = "1.0.0")]
454-
impl Shl<$f> for $t {
458+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
459+
impl const Shl<$f> for $t {
455460
type Output = $t;
456461

457462
#[inline]
@@ -461,7 +466,7 @@ macro_rules! shl_impl {
461466
}
462467
}
463468

464-
forward_ref_binop! { impl Shl, shl for $t, $f }
469+
forward_ref_binop! { impl const Shl, shl for $t, $f }
465470
};
466471
}
467472

@@ -569,7 +574,8 @@ pub trait Shr<Rhs = Self> {
569574
macro_rules! shr_impl {
570575
($t:ty, $f:ty) => {
571576
#[stable(feature = "rust1", since = "1.0.0")]
572-
impl Shr<$f> for $t {
577+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
578+
impl const Shr<$f> for $t {
573579
type Output = $t;
574580

575581
#[inline]
@@ -579,7 +585,7 @@ macro_rules! shr_impl {
579585
}
580586
}
581587

582-
forward_ref_binop! { impl Shr, shr for $t, $f }
588+
forward_ref_binop! { impl const Shr, shr for $t, $f }
583589
};
584590
}
585591

@@ -704,12 +710,13 @@ pub trait BitAndAssign<Rhs = Self> {
704710
macro_rules! bitand_assign_impl {
705711
($($t:ty)+) => ($(
706712
#[stable(feature = "op_assign_traits", since = "1.8.0")]
707-
impl BitAndAssign for $t {
713+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
714+
impl const BitAndAssign for $t {
708715
#[inline]
709716
fn bitand_assign(&mut self, other: $t) { *self &= other }
710717
}
711718

712-
forward_ref_op_assign! { impl BitAndAssign, bitand_assign for $t, $t }
719+
forward_ref_op_assign! { impl const BitAndAssign, bitand_assign for $t, $t }
713720
)+)
714721
}
715722

@@ -775,12 +782,13 @@ pub trait BitOrAssign<Rhs = Self> {
775782
macro_rules! bitor_assign_impl {
776783
($($t:ty)+) => ($(
777784
#[stable(feature = "op_assign_traits", since = "1.8.0")]
778-
impl BitOrAssign for $t {
785+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
786+
impl const BitOrAssign for $t {
779787
#[inline]
780788
fn bitor_assign(&mut self, other: $t) { *self |= other }
781789
}
782790

783-
forward_ref_op_assign! { impl BitOrAssign, bitor_assign for $t, $t }
791+
forward_ref_op_assign! { impl const BitOrAssign, bitor_assign for $t, $t }
784792
)+)
785793
}
786794

@@ -846,12 +854,13 @@ pub trait BitXorAssign<Rhs = Self> {
846854
macro_rules! bitxor_assign_impl {
847855
($($t:ty)+) => ($(
848856
#[stable(feature = "op_assign_traits", since = "1.8.0")]
849-
impl BitXorAssign for $t {
857+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
858+
impl const BitXorAssign for $t {
850859
#[inline]
851860
fn bitxor_assign(&mut self, other: $t) { *self ^= other }
852861
}
853862

854-
forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for $t, $t }
863+
forward_ref_op_assign! { impl const BitXorAssign, bitxor_assign for $t, $t }
855864
)+)
856865
}
857866

@@ -907,15 +916,16 @@ pub trait ShlAssign<Rhs = Self> {
907916
macro_rules! shl_assign_impl {
908917
($t:ty, $f:ty) => {
909918
#[stable(feature = "op_assign_traits", since = "1.8.0")]
910-
impl ShlAssign<$f> for $t {
919+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
920+
impl const ShlAssign<$f> for $t {
911921
#[inline]
912922
#[rustc_inherit_overflow_checks]
913923
fn shl_assign(&mut self, other: $f) {
914924
*self <<= other
915925
}
916926
}
917927

918-
forward_ref_op_assign! { impl ShlAssign, shl_assign for $t, $f }
928+
forward_ref_op_assign! { impl const ShlAssign, shl_assign for $t, $f }
919929
};
920930
}
921931

@@ -989,15 +999,16 @@ pub trait ShrAssign<Rhs = Self> {
989999
macro_rules! shr_assign_impl {
9901000
($t:ty, $f:ty) => {
9911001
#[stable(feature = "op_assign_traits", since = "1.8.0")]
992-
impl ShrAssign<$f> for $t {
1002+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
1003+
impl const ShrAssign<$f> for $t {
9931004
#[inline]
9941005
#[rustc_inherit_overflow_checks]
9951006
fn shr_assign(&mut self, other: $f) {
9961007
*self >>= other
9971008
}
9981009
}
9991010

1000-
forward_ref_op_assign! { impl ShrAssign, shr_assign for $t, $f }
1011+
forward_ref_op_assign! { impl const ShrAssign, shr_assign for $t, $f }
10011012
};
10021013
}
10031014

0 commit comments

Comments
 (0)
Please sign in to comment.