Skip to content

Commit 92a1f6d

Browse files
committed
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
2 parents 7bef1ff + 22c3db5 commit 92a1f6d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libcore/clone.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ impl<T> Clone for @mut T {
4848
fn clone(&self) -> @mut T { *self }
4949
}
5050

51+
impl<'self, T> Clone for &'self T {
52+
/// Return a shallow copy of the borrowed pointer.
53+
#[inline(always)]
54+
fn clone(&self) -> &'self T { *self }
55+
}
56+
5157
macro_rules! clone_impl(
5258
($t:ty) => {
5359
impl Clone for $t {
@@ -166,3 +172,11 @@ fn test_managed_mut_clone() {
166172
*b = 10;
167173
assert!(a == b);
168174
}
175+
176+
#[test]
177+
fn test_borrowed_clone() {
178+
let x = 5i;
179+
let y: &int = &x;
180+
let z: &int = (&y).clone();
181+
assert_eq!(*z, 5);
182+
}

0 commit comments

Comments
 (0)