summary refs log tree commit diff
path: root/src/libcore/clone.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-05-13 14:58:29 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-05-13 17:24:07 -0700
commitcbc31df4fc084b47a5c6456df2efb6e28b82a7da (patch)
treed978963435cc73d848ff8b936e9b0dba050b482b /src/libcore/clone.rs
parentcb115ac2d4f57d8b590c8d46d8f9e2958ed9a527 (diff)
downloadrust-cbc31df4fc084b47a5c6456df2efb6e28b82a7da.tar.gz
rust-cbc31df4fc084b47a5c6456df2efb6e28b82a7da.zip
std: Move the owned module from core to std
The compiler was updated to recognize that implementations for ty_uniq(..) are
allowed if the Box lang item is located in the current crate. This enforces the
idea that libcore cannot allocated, and moves all related trait implementations
from libcore to libstd.

This is a breaking change in that the AnyOwnExt trait has moved from the any
module to the owned module. Any previous users of std::any::AnyOwnExt should now
use std::owned::AnyOwnExt instead. This was done because the trait is intended
for Box traits and only Box traits.

[breaking-change]
Diffstat (limited to 'src/libcore/clone.rs')
-rw-r--r--src/libcore/clone.rs30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs
index 06cbaf19812..cd66beabc12 100644
--- a/src/libcore/clone.rs
+++ b/src/libcore/clone.rs
@@ -21,8 +21,6 @@ the `clone` method.
 
 */
 
-use owned::Box;
-
 /// A common trait for cloning an object.
 pub trait Clone {
     /// Returns a copy of the value. The contents of owned pointers
@@ -41,18 +39,6 @@ pub trait Clone {
     }
 }
 
-impl<T: Clone> Clone for Box<T> {
-    /// Return a copy of the owned box.
-    #[inline]
-    fn clone(&self) -> Box<T> { box {(**self).clone()} }
-
-    /// Perform copy-assignment from `source` by reusing the existing allocation.
-    #[inline]
-    fn clone_from(&mut self, source: &Box<T>) {
-        (**self).clone_from(&(**source));
-    }
-}
-
 impl<T> Clone for @T {
     /// Return a shallow copy of the managed box.
     #[inline]
@@ -129,12 +115,22 @@ extern_fn_clone!(A, B, C, D, E, F, G, H)
 #[cfg(test)]
 mod test {
     use prelude::*;
-    use owned::Box;
+    use realstd::owned::Box;
+
+    fn realclone<T: ::realstd::clone::Clone>(t: &T) -> T {
+        use realstd::clone::Clone;
+        t.clone()
+    }
+
+    fn realclone_from<T: ::realstd::clone::Clone>(t1: &mut T, t2: &T) {
+        use realstd::clone::Clone;
+        t1.clone_from(t2)
+    }
 
     #[test]
     fn test_owned_clone() {
         let a = box 5i;
-        let b: Box<int> = a.clone();
+        let b: Box<int> = realclone(&a);
         assert_eq!(a, b);
     }
 
@@ -157,7 +153,7 @@ mod test {
     fn test_clone_from() {
         let a = box 5;
         let mut b = box 10;
-        b.clone_from(&a);
+        realclone_from(&mut b, &a);
         assert_eq!(*b, 5);
     }