diff options
| author | bors <bors@rust-lang.org> | 2013-05-16 01:07:45 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-05-16 01:07:45 -0700 |
| commit | 92a1f6de97c8360c77763d4e6ef9fc6b6775cfc0 (patch) | |
| tree | 976e327e08afe3886bb8c71e6efb27d5e1bda638 | |
| parent | 7bef1ff4b19805f6b452697ad5febd4965cfaea3 (diff) | |
| parent | 22c3db5df786316c7a7c702aad93e9f0e9a4061d (diff) | |
| download | rust-92a1f6de97c8360c77763d4e6ef9fc6b6775cfc0.tar.gz rust-92a1f6de97c8360c77763d4e6ef9fc6b6775cfc0.zip | |
auto merge of #6509 : thestinger/rust/clone, r=nikomatsakis
somewhat annoying to actually call thanks to auto-deref, but it does let `deriving(Clone)` work
| -rw-r--r-- | src/libcore/clone.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs index 9c1c83b47ca..4d2b5998b44 100644 --- a/src/libcore/clone.rs +++ b/src/libcore/clone.rs @@ -48,6 +48,12 @@ impl<T> Clone for @mut T { fn clone(&self) -> @mut T { *self } } +impl<'self, T> Clone for &'self T { + /// Return a shallow copy of the borrowed pointer. + #[inline(always)] + fn clone(&self) -> &'self T { *self } +} + macro_rules! clone_impl( ($t:ty) => { impl Clone for $t { @@ -166,3 +172,11 @@ fn test_managed_mut_clone() { *b = 10; assert!(a == b); } + +#[test] +fn test_borrowed_clone() { + let x = 5i; + let y: &int = &x; + let z: &int = (&y).clone(); + assert_eq!(*z, 5); +} |
