Skip to content

Commit 443a2ac

Browse files
authored
Rollup merge of rust-lang#35793 - matthew-piziak:add-rhs-example, r=steveklabnik
demonstrate `RHS != Self` use cases for `Add` and `Sub`
2 parents 089b84d + 96bd6cf commit 443a2ac

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libcore/ops.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ macro_rules! forward_ref_binop {
211211
/// Point { x: 3, y: 3 });
212212
/// }
213213
/// ```
214+
///
215+
/// Note that `RHS = Self` by default, but this is not mandatory. For example,
216+
/// [std::time::SystemTime] implements `Add<Duration>`, which permits
217+
/// operations of the form `SystemTime = SystemTime + Duration`.
218+
///
219+
/// [std::time::SystemTime]: ../../time/struct.SystemTime.html
214220
#[lang = "add"]
215221
#[stable(feature = "rust1", since = "1.0.0")]
216222
pub trait Add<RHS=Self> {
@@ -265,6 +271,12 @@ add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
265271
/// Foo - Foo;
266272
/// }
267273
/// ```
274+
///
275+
/// Note that `RHS = Self` by default, but this is not mandatory. For example,
276+
/// [std::time::SystemTime] implements `Sub<Duration>`, which permits
277+
/// operations of the form `SystemTime = SystemTime - Duration`.
278+
///
279+
/// [std::time::SystemTime]: ../../time/struct.SystemTime.html
268280
#[lang = "sub"]
269281
#[stable(feature = "rust1", since = "1.0.0")]
270282
pub trait Sub<RHS=Self> {

0 commit comments

Comments
 (0)