Skip to content

Commit

Permalink
auto merge of #5751 : metajack/rust/at-clones, r=thestinger
Browse files Browse the repository at this point in the history
The borrowck-borrow-from-expr-block test had to be updated. I'm not sure why
it compiled before since ~int was already clonable.
  • Loading branch information
bors committed Apr 6, 2013
2 parents 28527ce + d375171 commit d09835d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
33 changes: 32 additions & 1 deletion src/libcore/clone.rs
Original file line number Diff line number Diff line change
@@ -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.
//
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions src/test/run-pass/borrowck-borrow-from-expr-block.rs
Original file line number Diff line number Diff line change
@@ -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.
//
Expand All @@ -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);
Expand Down

0 comments on commit d09835d

Please sign in to comment.