Implement Clone for @ and @mut types.
The borrowck-borrow-from-expr-block test had to be updated. I'm not sure why it compiled before since ~int was already clonable.
This commit is contained in:
parent
babe506333
commit
b22a06000d
@ -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 {
|
||||
|
@ -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);
|
||||
|
27
src/test/run-pass/clones.rs
Normal file
27
src/test/run-pass/clones.rs
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
let a : ~int = ~5i;
|
||||
let b : ~int = a.clone();
|
||||
|
||||
debug!(fmt!("a: %?, b: %?", a, b));
|
||||
|
||||
let a : @int = @5i;
|
||||
let b : @int = a.clone();
|
||||
|
||||
debug!(fmt!("a: %?, b: %?", a, b));
|
||||
|
||||
let a : @mut int = @mut 5i;
|
||||
let b : @mut int = a.clone();
|
||||
*b = 6;
|
||||
|
||||
debug!(fmt!("a: %?, b: %?", a, b));
|
||||
}
|
Loading…
Reference in New Issue
Block a user