From cbc31df4fc084b47a5c6456df2efb6e28b82a7da Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 13 May 2014 14:58:29 -0700 Subject: 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] --- src/libcore/clone.rs | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'src/libcore/clone.rs') 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 Clone for Box { - /// Return a copy of the owned box. - #[inline] - fn clone(&self) -> Box { box {(**self).clone()} } - - /// Perform copy-assignment from `source` by reusing the existing allocation. - #[inline] - fn clone_from(&mut self, source: &Box) { - (**self).clone_from(&(**source)); - } -} - impl 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: &T) -> T { + use realstd::clone::Clone; + t.clone() + } + + fn realclone_from(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 = a.clone(); + let b: Box = 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); } -- cgit 1.4.1-3-g733a5