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
This commit is contained in:
commit
92a1f6de97
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user