Skip to content

Commit 22c3db5

Browse files
committed
add a Clone impl for borrowed pointers
1 parent 4e82610 commit 22c3db5

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
@@ -51,6 +51,12 @@ impl<T> Clone for @mut T {
5151
fn clone(&self) -> @mut T { *self }
5252
}
5353

54+
impl<'self, T> Clone for &'self T {
55+
/// Return a shallow copy of the borrowed pointer.
56+
#[inline(always)]
57+
fn clone(&self) -> &'self T { *self }
58+
}
59+
5460
macro_rules! clone_impl(
5561
($t:ty) => {
5662
impl Clone for $t {
@@ -102,3 +108,11 @@ fn test_managed_mut_clone() {
102108
*b = 10;
103109
assert!(a == b);
104110
}
111+
112+
#[test]
113+
fn test_borrowed_clone() {
114+
let x = 5i;
115+
let y: &int = &x;
116+
let z: &int = (&y).clone();
117+
assert_eq!(*z, 5);
118+
}

0 commit comments

Comments
 (0)