diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-07-03 09:59:24 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-03 09:59:24 -0400 |
| commit | 8ca4a6a48644cb923437d1d81c1c61164fb66623 (patch) | |
| tree | 1196c6c51cc97eb798105a5edb249881650b1d93 /src | |
| parent | d1db5e4a85a0124c96ef99d185dba708ca8398fe (diff) | |
| parent | fc70c37d167237023df1e75d154d1e6bebd44aee (diff) | |
Rollup merge of #62250 - czipperz:improve-box-clone-doctests, r=GuillaumeGomez
Improve box clone doctests to ensure the documentation is valid
Diffstat (limited to 'src')
| -rw-r--r-- | src/liballoc/boxed.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 9109a730cce..19b0f82db43 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -367,12 +367,19 @@ impl<T: Clone> Clone for Box<T> { /// ``` /// let x = Box::new(5); /// let y = x.clone(); + /// + /// // The value is the same + /// assert_eq!(x, y); + /// + /// // But they are unique objects + /// assert_ne!(&*x as *const i32, &*y as *const i32); /// ``` #[rustfmt::skip] #[inline] fn clone(&self) -> Box<T> { box { (**self).clone() } } + /// Copies `source`'s contents into `self` without creating a new allocation. /// /// # Examples @@ -380,10 +387,15 @@ impl<T: Clone> Clone for Box<T> { /// ``` /// let x = Box::new(5); /// let mut y = Box::new(10); + /// let yp: *const i32 = &*y; /// /// y.clone_from(&x); /// - /// assert_eq!(*y, 5); + /// // The value is the same + /// assert_eq!(x, y); + /// + /// // And no allocation occurred + /// assert_eq!(yp, &*y); /// ``` #[inline] fn clone_from(&mut self, source: &Box<T>) { |
