Skip to content

Commit ec220b6

Browse files
committed
constify Add
1 parent d6ee9db commit ec220b6

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
#![feature(const_is_char_boundary)]
176176
#![feature(const_precise_live_drops)]
177177
#![feature(const_str_split_at)]
178+
#![feature(const_trait_impl)]
178179
#![feature(decl_macro)]
179180
#![feature(deprecated_suggestion)]
180181
#![feature(doc_cfg)]

core/src/ops/arith.rs

+13
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
append_const_msg
7474
)]
7575
#[doc(alias = "+")]
76+
#[cfg_attr(not(bootstrap), const_trait)]
7677
pub trait Add<Rhs = Self> {
7778
/// The resulting type after applying the `+` operator.
7879
#[stable(feature = "rust1", since = "1.0.0")]
@@ -94,6 +95,7 @@ pub trait Add<Rhs = Self> {
9495
macro_rules! add_impl {
9596
($($t:ty)*) => ($(
9697
#[stable(feature = "rust1", since = "1.0.0")]
98+
#[cfg(bootstrap)]
9799
impl Add for $t {
98100
type Output = $t;
99101

@@ -103,6 +105,17 @@ macro_rules! add_impl {
103105
fn add(self, other: $t) -> $t { self + other }
104106
}
105107

108+
#[stable(feature = "rust1", since = "1.0.0")]
109+
#[cfg(not(bootstrap))]
110+
impl const Add for $t {
111+
type Output = $t;
112+
113+
#[inline]
114+
#[track_caller]
115+
#[rustc_inherit_overflow_checks]
116+
fn add(self, other: $t) -> $t { self + other }
117+
}
118+
106119
forward_ref_binop! { impl Add, add for $t, $t }
107120
)*)
108121
}

0 commit comments

Comments
 (0)