diff options
| author | bors <bors@rust-lang.org> | 2013-04-06 00:06:47 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-04-06 00:06:47 -0700 |
| commit | d09835d2e3c0cb3227baec0ba6f1b23d7c95f474 (patch) | |
| tree | 4d65504cfa5a6595d8fd1c1d343b5448004db786 | |
| parent | 28527ce8a272f117e6dcc25725452ba6430f6694 (diff) | |
| parent | d375171fd44247bff3e355fb82d88b83f14da442 (diff) | |
| download | rust-d09835d2e3c0cb3227baec0ba6f1b23d7c95f474.tar.gz rust-d09835d2e3c0cb3227baec0ba6f1b23d7c95f474.zip | |
auto merge of #5751 : metajack/rust/at-clones, r=thestinger
The borrowck-borrow-from-expr-block test had to be updated. I'm not sure why it compiled before since ~int was already clonable.
| -rw-r--r-- | src/libcore/clone.rs | 33 | ||||
| -rw-r--r-- | src/test/run-pass/borrowck-borrow-from-expr-block.rs | 4 |
2 files changed, 34 insertions, 3 deletions
diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs index 7b86355c91e..c4b5bb8d98b 100644 --- a/src/libcore/clone.rs +++ b/src/libcore/clone.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -36,6 +36,16 @@ impl<T:Clone> Clone for ~T { fn clone(&self) -> ~T { ~(**self).clone() } } +impl<T:Clone> Clone for @T { + #[inline(always)] + fn clone(&self) -> @T { @(**self).clone() } +} + +impl<T:Clone> Clone for @mut T { + #[inline(always)] + fn clone(&self) -> @mut T { @mut (**self).clone() } +} + macro_rules! clone_impl( ($t:ty) => { impl Clone for $t { @@ -63,3 +73,24 @@ clone_impl!(f64) clone_impl!(bool) clone_impl!(char) + +#[test] +fn test_owned_clone() { + let a : ~int = ~5i; + let b : ~int = a.clone(); + assert!(a == b); +} + +#[test] +fn test_managed_clone() { + let a : @int = @5i; + let b : @int = a.clone(); + assert!(a == b); +} + +#[test] +fn test_managed_mut_clone() { + let a : @int = @5i; + let b : @int = a.clone(); + assert!(a == b); +} diff --git a/src/test/run-pass/borrowck-borrow-from-expr-block.rs b/src/test/run-pass/borrowck-borrow-from-expr-block.rs index 401985023bc..077de5c7eb1 100644 --- a/src/test/run-pass/borrowck-borrow-from-expr-block.rs +++ b/src/test/run-pass/borrowck-borrow-from-expr-block.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,7 +13,7 @@ fn borrow(x: &int, f: &fn(x: &int)) { } fn test1(x: @~int) { - do borrow(&*x.clone()) |p| { + do borrow(&**x.clone()) |p| { let x_a = ptr::addr_of(&(**x)); assert!((x_a as uint) != ptr::to_uint(p)); assert!(unsafe{*x_a} == *p); |
