about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorChris Gregory <czipperz@gmail.com>2019-06-30 11:56:21 -0700
committerChris Gregory <czipperz@gmail.com>2019-06-30 11:56:21 -0700
commitfc70c37d167237023df1e75d154d1e6bebd44aee (patch)
tree4977e4abea5429312160bbd20d28e98d0ba387d9 /src/liballoc
parent0af8e872ea5ac77effa59f8d3f8794f12cb8865c (diff)
downloadrust-fc70c37d167237023df1e75d154d1e6bebd44aee.tar.gz
rust-fc70c37d167237023df1e75d154d1e6bebd44aee.zip
Improve box clone doctests to ensure the documentation is valid
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/boxed.rs14
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>) {