1
Fork 0

auto merge of #5404 : bstrie/rust/decopy, r=pcwalton

Also turn `copy` into `.clone()` in much of run-pass.
This commit is contained in:
bors 2013-03-15 20:15:44 -07:00
commit 6f1e8ef71a
46 changed files with 115 additions and 86 deletions

View file

@ -20,6 +20,11 @@ impl Clone for () {
fn clone(&self) -> () { () } fn clone(&self) -> () { () }
} }
impl<T:Clone> Clone for ~T {
#[inline(always)]
fn clone(&self) -> ~T { ~(**self).clone() }
}
macro_rules! clone_impl( macro_rules! clone_impl(
($t:ty) => { ($t:ty) => {
impl Clone for $t { impl Clone for $t {

View file

@ -20,6 +20,7 @@
use at_vec; use at_vec;
use cast; use cast;
use char; use char;
use clone::Clone;
use cmp::{Equiv, TotalOrd, Ordering, Less, Equal, Greater}; use cmp::{Equiv, TotalOrd, Ordering, Less, Equal, Greater};
use libc; use libc;
use option::{None, Option, Some}; use option::{None, Option, Some};
@ -2436,6 +2437,13 @@ impl OwnedStr for ~str {
} }
} }
impl Clone for ~str {
#[inline(always)]
fn clone(&self) -> ~str {
self.to_str() // hilarious
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use char; use char;

View file

@ -68,11 +68,11 @@ unsafe fn global_data_clone_create_<T:Owned + Clone>(
match value { match value {
None => { None => {
let value = create(); let value = create();
clone_value = Some(value.clone()); clone_value = Some((*value).clone());
Some(value) Some(value)
} }
Some(value) => { Some(value) => {
clone_value = Some(value.clone()); clone_value = Some((*value).clone());
Some(value) Some(value)
} }
} }
@ -193,7 +193,7 @@ fn get_global_state() -> Exclusive<GlobalState> {
// Successfully installed the global pointer // Successfully installed the global pointer
// Take a handle to return // Take a handle to return
let clone = state.clone(); let clone = (*state).clone();
// Install a runtime exit function to destroy the global object // Install a runtime exit function to destroy the global object
do at_exit { do at_exit {

View file

@ -15,6 +15,7 @@
use container::{Container, Mutable}; use container::{Container, Mutable};
use cast; use cast;
use cmp::{Eq, Equiv, Ord, TotalOrd, Ordering, Less, Equal, Greater}; use cmp::{Eq, Equiv, Ord, TotalOrd, Ordering, Less, Equal, Greater};
use clone::Clone;
use iter::BaseIter; use iter::BaseIter;
use iter; use iter;
use kinds::Copy; use kinds::Copy;
@ -2501,6 +2502,18 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for @[A] {
} }
} }
impl<A:Clone> Clone for ~[A] {
#[inline]
fn clone(&self) -> ~[A] {
let mut dolly = ~[];
vec::reserve(&mut dolly, self.len());
for self.each |item| {
dolly.push(item.clone());
}
return dolly;
}
}
// ___________________________________________________________________________ // ___________________________________________________________________________
#[cfg(test)] #[cfg(test)]

View file

@ -572,7 +572,7 @@ mod tests {
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_rw_arc_poison_wr() { pub fn test_rw_arc_poison_wr() {
let arc = ~RWARC(1); let arc = ~RWARC(1);
let arc2 = ~arc.clone(); let arc2 = (*arc).clone();
do task::try || { do task::try || {
do arc2.write |one| { do arc2.write |one| {
fail_unless!(*one == 2); fail_unless!(*one == 2);
@ -585,7 +585,7 @@ mod tests {
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_rw_arc_poison_ww() { pub fn test_rw_arc_poison_ww() {
let arc = ~RWARC(1); let arc = ~RWARC(1);
let arc2 = ~arc.clone(); let arc2 = (*arc).clone();
do task::try || { do task::try || {
do arc2.write |one| { do arc2.write |one| {
fail_unless!(*one == 2); fail_unless!(*one == 2);
@ -598,7 +598,7 @@ mod tests {
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_rw_arc_poison_dw() { pub fn test_rw_arc_poison_dw() {
let arc = ~RWARC(1); let arc = ~RWARC(1);
let arc2 = ~arc.clone(); let arc2 = (*arc).clone();
do task::try || { do task::try || {
do arc2.write_downgrade |write_mode| { do arc2.write_downgrade |write_mode| {
do (&write_mode).write |one| { do (&write_mode).write |one| {
@ -613,7 +613,7 @@ mod tests {
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_rw_arc_no_poison_rr() { pub fn test_rw_arc_no_poison_rr() {
let arc = ~RWARC(1); let arc = ~RWARC(1);
let arc2 = ~arc.clone(); let arc2 = (*arc).clone();
do task::try || { do task::try || {
do arc2.read |one| { do arc2.read |one| {
fail_unless!(*one == 2); fail_unless!(*one == 2);
@ -626,7 +626,7 @@ mod tests {
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_rw_arc_no_poison_rw() { pub fn test_rw_arc_no_poison_rw() {
let arc = ~RWARC(1); let arc = ~RWARC(1);
let arc2 = ~arc.clone(); let arc2 = (*arc).clone();
do task::try || { do task::try || {
do arc2.read |one| { do arc2.read |one| {
fail_unless!(*one == 2); fail_unless!(*one == 2);
@ -639,7 +639,7 @@ mod tests {
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_rw_arc_no_poison_dr() { pub fn test_rw_arc_no_poison_dr() {
let arc = ~RWARC(1); let arc = ~RWARC(1);
let arc2 = ~arc.clone(); let arc2 = (*arc).clone();
do task::try || { do task::try || {
do arc2.write_downgrade |write_mode| { do arc2.write_downgrade |write_mode| {
let read_mode = arc2.downgrade(write_mode); let read_mode = arc2.downgrade(write_mode);
@ -655,7 +655,7 @@ mod tests {
#[test] #[test]
pub fn test_rw_arc() { pub fn test_rw_arc() {
let arc = ~RWARC(0); let arc = ~RWARC(0);
let arc2 = ~arc.clone(); let arc2 = (*arc).clone();
let (p,c) = comm::stream(); let (p,c) = comm::stream();
do task::spawn || { do task::spawn || {
@ -673,7 +673,7 @@ mod tests {
// Readers try to catch the writer in the act // Readers try to catch the writer in the act
let mut children = ~[]; let mut children = ~[];
for 5.times { for 5.times {
let arc3 = ~arc.clone(); let arc3 = (*arc).clone();
do task::task().future_result(|+r| children.push(r)).spawn do task::task().future_result(|+r| children.push(r)).spawn
|| { || {
do arc3.read |num| { do arc3.read |num| {
@ -704,7 +704,7 @@ mod tests {
for 10.times { for 10.times {
let ((rp1,rc1),(rp2,rc2)) = (comm::stream(),comm::stream()); let ((rp1,rc1),(rp2,rc2)) = (comm::stream(),comm::stream());
reader_convos.push((rc1, rp2)); reader_convos.push((rc1, rp2));
let arcn = ~arc.clone(); let arcn = (*arc).clone();
do task::spawn || { do task::spawn || {
rp1.recv(); // wait for downgrader to give go-ahead rp1.recv(); // wait for downgrader to give go-ahead
do arcn.read |state| { do arcn.read |state| {
@ -715,7 +715,7 @@ mod tests {
} }
// Writer task // Writer task
let arc2 = ~arc.clone(); let arc2 = (*arc).clone();
let ((wp1,wc1),(wp2,wc2)) = (comm::stream(),comm::stream()); let ((wp1,wc1),(wp2,wc2)) = (comm::stream(),comm::stream());
do task::spawn || { do task::spawn || {
wp1.recv(); wp1.recv();

View file

@ -827,7 +827,7 @@ mod tests {
// "load tmp = move ptr; inc tmp; store ptr <- tmp" dance. // "load tmp = move ptr; inc tmp; store ptr <- tmp" dance.
let (p,c) = comm::stream(); let (p,c) = comm::stream();
let m = ~Mutex(); let m = ~Mutex();
let m2 = ~m.clone(); let m2 = m.clone();
let mut sharedstate = ~0; let mut sharedstate = ~0;
let ptr = ptr::addr_of(&(*sharedstate)); let ptr = ptr::addr_of(&(*sharedstate));
do task::spawn || { do task::spawn || {
@ -1105,13 +1105,13 @@ mod tests {
// Test mutual exclusion between readers and writers. Just like the // Test mutual exclusion between readers and writers. Just like the
// mutex mutual exclusion test, a ways above. // mutex mutual exclusion test, a ways above.
let (p,c) = comm::stream(); let (p,c) = comm::stream();
let x2 = ~x.clone(); let x2 = (*x).clone();
let mut sharedstate = ~0; let mut sharedstate = ~0;
let ptr = ptr::addr_of(&(*sharedstate)); let ptr = ptr::addr_of(&(*sharedstate));
do task::spawn || { do task::spawn || {
let sharedstate: &mut int = let sharedstate: &mut int =
unsafe { cast::reinterpret_cast(&ptr) }; unsafe { cast::reinterpret_cast(&ptr) };
access_shared(sharedstate, x2, mode1, 10); access_shared(sharedstate, &x2, mode1, 10);
c.send(()); c.send(());
} }
access_shared(sharedstate, x, mode2, 10); access_shared(sharedstate, x, mode2, 10);
@ -1150,14 +1150,14 @@ mod tests {
mode2: RWlockMode, mode2: RWlockMode,
make_mode2_go_first: bool) { make_mode2_go_first: bool) {
// Much like sem_multi_resource. // Much like sem_multi_resource.
let x2 = ~x.clone(); let x2 = (*x).clone();
let (p1,c1) = comm::stream(); let (p1,c1) = comm::stream();
let (p2,c2) = comm::stream(); let (p2,c2) = comm::stream();
do task::spawn || { do task::spawn || {
if !make_mode2_go_first { if !make_mode2_go_first {
let _ = p2.recv(); // parent sends to us once it locks, or ... let _ = p2.recv(); // parent sends to us once it locks, or ...
} }
do lock_rwlock_in_mode(x2, mode2) { do lock_rwlock_in_mode(&x2, mode2) {
if make_mode2_go_first { if make_mode2_go_first {
c1.send(()); // ... we send to it once we lock c1.send(()); // ... we send to it once we lock
} }
@ -1207,7 +1207,7 @@ mod tests {
// Child wakes up parent // Child wakes up parent
do x.write_cond |cond| { do x.write_cond |cond| {
let x2 = ~x.clone(); let x2 = (*x).clone();
do task::spawn || { do task::spawn || {
do x2.write_cond |cond| { do x2.write_cond |cond| {
let woken = cond.signal(); let woken = cond.signal();
@ -1218,7 +1218,7 @@ mod tests {
} }
// Parent wakes up child // Parent wakes up child
let (port,chan) = comm::stream(); let (port,chan) = comm::stream();
let x3 = ~x.clone(); let x3 = (*x).clone();
do task::spawn || { do task::spawn || {
do x3.write_cond |cond| { do x3.write_cond |cond| {
chan.send(()); chan.send(());
@ -1253,11 +1253,11 @@ mod tests {
let mut ports = ~[]; let mut ports = ~[];
for num_waiters.times { for num_waiters.times {
let xi = ~x.clone(); let xi = (*x).clone();
let (port, chan) = comm::stream(); let (port, chan) = comm::stream();
ports.push(port); ports.push(port);
do task::spawn || { do task::spawn || {
do lock_cond(xi, dg1) |cond| { do lock_cond(&xi, dg1) |cond| {
chan.send(()); chan.send(());
cond.wait(); cond.wait();
chan.send(()); chan.send(());
@ -1289,10 +1289,10 @@ mod tests {
pub fn rwlock_kill_helper(mode1: RWlockMode, mode2: RWlockMode) { pub fn rwlock_kill_helper(mode1: RWlockMode, mode2: RWlockMode) {
// Mutex must get automatically unlocked if failed/killed within. // Mutex must get automatically unlocked if failed/killed within.
let x = ~RWlock(); let x = ~RWlock();
let x2 = ~x.clone(); let x2 = (*x).clone();
let result: result::Result<(),()> = do task::try || { let result: result::Result<(),()> = do task::try || {
do lock_rwlock_in_mode(x2, mode1) { do lock_rwlock_in_mode(&x2, mode1) {
fail!(); fail!();
} }
}; };

View file

@ -63,7 +63,7 @@ pub fn analyze(proto: protocol, _cx: @ext_ctxt) {
debug!("colive iteration %?", i); debug!("colive iteration %?", i);
let mut new_colive = ~[]; let mut new_colive = ~[];
for colive.eachi |i, this_colive| { for colive.eachi |i, this_colive| {
let mut result = ~this_colive.clone(); let mut result = this_colive.clone();
let this = proto.get_state_by_id(i); let this = proto.get_state_by_id(i);
for this_colive.ones |j| { for this_colive.ones |j| {
let next = proto.get_state_by_id(j); let next = proto.get_state_by_id(j);

View file

@ -11,7 +11,7 @@
fn foo(x: Option<~int>, b: bool) -> int { fn foo(x: Option<~int>, b: bool) -> int {
match x { match x {
None => { 1 } None => { 1 }
Some(copy x) if b => { *x } Some(ref x) if b => { *x.clone() }
Some(_) => { 0 } Some(_) => { 0 }
} }
} }

View file

@ -43,7 +43,7 @@ pub fn main() {
// Call a method // Call a method
for x.iterate() |y| { fail_unless!(x[*y] == *y); } for x.iterate() |y| { fail_unless!(x[*y] == *y); }
// Call a parameterized function // Call a parameterized function
fail_unless!(length(copy x) == vec::len(x)); fail_unless!(length(x.clone()) == vec::len(x));
// Call a parameterized function, with type arguments that require // Call a parameterized function, with type arguments that require
// a borrow // a borrow
fail_unless!(length::<int, &[int]>(x) == vec::len(x)); fail_unless!(length::<int, &[int]>(x) == vec::len(x));

View file

@ -15,8 +15,8 @@ fn iter_vec<T>(v: ~[T], f: &fn(&T)) { for v.each |x| { f(x); } }
pub fn main() { pub fn main() {
let v = ~[1, 2, 3, 4, 5]; let v = ~[1, 2, 3, 4, 5];
let mut sum = 0; let mut sum = 0;
iter_vec(copy v, |i| { iter_vec(v.clone(), |i| {
iter_vec(copy v, |j| { iter_vec(v.clone(), |j| {
sum += *i * *j; sum += *i * *j;
}); });
}); });

View file

@ -15,6 +15,6 @@ pub fn main() {
vec::map2(~[1, 2, 3, 4, 5], vec::map2(~[1, 2, 3, 4, 5],
~[true, false, false, true, true], ~[true, false, false, true, true],
|i, b| if *b { -(*i) } else { *i } ); |i, b| if *b { -(*i) } else { *i } );
error!(copy v); error!(v.clone());
fail_unless!((v == ~[-1, 2, 3, -4, -5])); fail_unless!((v == ~[-1, 2, 3, -4, -5]));
} }

View file

@ -13,7 +13,7 @@ fn borrow(x: &int, f: &fn(x: &int)) {
} }
fn test1(x: @~int) { fn test1(x: @~int) {
do borrow(copy *x) |p| { do borrow(&*x.clone()) |p| {
let x_a = ptr::addr_of(&(**x)); let x_a = ptr::addr_of(&(**x));
fail_unless!((x_a as uint) != ptr::to_uint(p)); fail_unless!((x_a as uint) != ptr::to_uint(p));
fail_unless!(unsafe{*x_a} == *p); fail_unless!(unsafe{*x_a} == *p);

View file

@ -13,7 +13,7 @@
fn switcher(x: Option<@int>) { fn switcher(x: Option<@int>) {
let mut x = x; let mut x = x;
match x { match x {
Some(@y) => { copy y; x = None; } Some(@y) => { y.clone(); x = None; }
None => { } None => { }
} }
} }

View file

@ -22,7 +22,7 @@ mod kitty {
} }
pub impl cat { pub impl cat {
fn get_name(&self) -> ~str { copy self.name } fn get_name(&self) -> ~str { self.name.clone() }
} }
pub fn cat(in_name: ~str) -> cat { pub fn cat(in_name: ~str) -> cat {

View file

@ -53,7 +53,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
cat { cat {
meows: in_x, meows: in_x,
how_hungry: in_y, how_hungry: in_y,
name: copy in_name name: in_name.clone()
} }
} }

View file

@ -9,8 +9,6 @@
// except according to those terms. // except according to those terms.
// xfail-fast // xfail-fast
use core::to_str::*;
struct cat { struct cat {
priv meows : uint, priv meows : uint,
@ -53,7 +51,12 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
} }
impl ToStr for cat { impl ToStr for cat {
pure fn to_str(&self) -> ~str { copy self.name } pure fn to_str(&self) -> ~str {
// FIXME #5384: this unsafe block is to work around purity
unsafe {
self.name.clone()
}
}
} }
fn print_out(thing: @ToStr, expected: ~str) { fn print_out(thing: @ToStr, expected: ~str) {

View file

@ -13,9 +13,9 @@
// -*- rust -*- // -*- rust -*-
type compare<T> = @fn(~T, ~T) -> bool; type compare<T> = @fn(~T, ~T) -> bool;
fn test_generic<T:Copy>(expected: ~T, eq: compare<T>) { fn test_generic<T:Copy+Clone>(expected: ~T, eq: compare<T>) {
let actual: ~T = match true { let actual: ~T = match true {
true => { copy expected }, true => { expected.clone() },
_ => fail!(~"wat") _ => fail!(~"wat")
}; };
fail_unless!((eq(expected, actual))); fail_unless!((eq(expected, actual)));

View file

@ -13,9 +13,9 @@
type compare<T> = @fn(T, T) -> bool; type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, eq: compare<T>) { fn test_generic<T:Copy+Clone>(expected: T, eq: compare<T>) {
let actual: T = match true { let actual: T = match true {
true => copy expected, true => expected.clone(),
_ => fail!(~"wat") _ => fail!(~"wat")
}; };
fail_unless!((eq(expected, actual))); fail_unless!((eq(expected, actual)));

View file

@ -13,8 +13,8 @@
// -*- rust -*- // -*- rust -*-
type compare<T> = @fn(~T, ~T) -> bool; type compare<T> = @fn(~T, ~T) -> bool;
fn test_generic<T:Copy>(expected: ~T, eq: compare<T>) { fn test_generic<T:Copy+Clone>(expected: ~T, eq: compare<T>) {
let actual: ~T = { copy expected }; let actual: ~T = { expected.clone() };
fail_unless!((eq(expected, actual))); fail_unless!((eq(expected, actual)));
} }

View file

@ -14,7 +14,7 @@ fn id<T:Copy + Owned>(t: T) -> T { return t; }
pub fn main() { pub fn main() {
let expected = ~100; let expected = ~100;
let actual = id::<~int>(copy expected); let actual = id::<~int>(expected.clone());
debug!(*actual); debug!(*actual);
fail_unless!((*expected == *actual)); fail_unless!((*expected == *actual));
} }

View file

@ -38,8 +38,8 @@ mod map_reduce {
fn start_mappers(ctrl: SharedChan<ctrl_proto>, inputs: ~[~str]) { fn start_mappers(ctrl: SharedChan<ctrl_proto>, inputs: ~[~str]) {
for inputs.each |i| { for inputs.each |i| {
let ctrl = ctrl.clone(); let ctrl = ctrl.clone();
let i = copy *i; let i = i.clone();
task::spawn(|| map_task(ctrl.clone(), copy i) ); task::spawn(|| map_task(ctrl.clone(), i.clone()) );
} }
} }
@ -79,7 +79,7 @@ mod map_reduce {
reducers = oldmap::HashMap(); reducers = oldmap::HashMap();
start_mappers(ctrl_chan, copy inputs); start_mappers(ctrl_chan, inputs.clone());
let mut num_mappers = vec::len(inputs) as int; let mut num_mappers = vec::len(inputs) as int;

View file

@ -20,7 +20,7 @@ impl Drop for socket {
pub impl socket { pub impl socket {
fn set_identity(&self) { fn set_identity(&self) {
do closure { do closure {
setsockopt_bytes(copy self.sock) setsockopt_bytes(self.sock.clone())
} }
} }
} }

View file

@ -14,5 +14,5 @@ fn a_val(&&x: ~int, +y: ~int) -> int {
pub fn main() { pub fn main() {
let z = ~22; let z = ~22;
a_val(copy z, copy z); a_val(z.clone(), z.clone());
} }

View file

@ -27,6 +27,6 @@ pub fn main() {
let v = ~[~"123", ~"abc"]; let v = ~[~"123", ~"abc"];
node.content = ~[~"123", ~"abc"]; node.content = ~[~"123", ~"abc"];
print_str_vector(v); print_str_vector(v);
print_str_vector(copy node.content); print_str_vector(node.content.clone());
} }

View file

@ -19,7 +19,7 @@ fn foo(name: ~str, samples_chan: Chan<Msg>) {
for uint::range(0, buffer.len()) for uint::range(0, buffer.len())
|i| {error!("%?: %f", i, buffer[i])} |i| {error!("%?: %f", i, buffer[i])}
}; };
samples_chan.send(GetSamples(copy name, callback)); samples_chan.send(GetSamples(name.clone(), callback));
}; };
} }

View file

@ -14,7 +14,7 @@ fn parse_args() -> ~str {
let mut n = 0; let mut n = 0;
while n < args.len() { while n < args.len() {
match copy args[n] { match args[n].clone() {
~"-v" => (), ~"-v" => (),
s => { s => {
return s; return s;

View file

@ -11,7 +11,7 @@
// xfail-test // xfail-test
pub fn main() { pub fn main() {
for os::args().each |arg| { for os::args().each |arg| {
match copy *arg { match arg.clone() {
s => { } s => { }
} }
} }

View file

@ -10,7 +10,7 @@
fn test_stack_assign() { fn test_stack_assign() {
let s: ~str = ~"a"; let s: ~str = ~"a";
debug!(copy s); debug!(s.clone());
let t: ~str = ~"a"; let t: ~str = ~"a";
fail_unless!((s == t)); fail_unless!((s == t));
let u: ~str = ~"b"; let u: ~str = ~"b";
@ -49,7 +49,7 @@ fn test_append() {
let mut s = ~"a"; let mut s = ~"a";
s += ~"b"; s += ~"b";
debug!(copy s); debug!(s.clone());
fail_unless!((s == ~"ab")); fail_unless!((s == ~"ab"));
let mut s = ~"c"; let mut s = ~"c";

View file

@ -14,7 +14,7 @@ struct A { a: ~int }
fn foo() -> @fn() -> int { fn foo() -> @fn() -> int {
let k = ~22; let k = ~22;
let _u = A {a: copy k}; let _u = A {a: k.clone()};
let result: @fn() -> int = || 22; let result: @fn() -> int = || 22;
result result
} }

View file

@ -15,6 +15,6 @@ struct A { a: ~int }
pub fn main() { pub fn main() {
fn invoke(f: @fn()) { f(); } fn invoke(f: @fn()) { f(); }
let k = ~22; let k = ~22;
let _u = A {a: copy k}; let _u = A {a: k.clone()};
invoke(|| error!(copy k) ) invoke(|| error!(k.clone()) )
} }

View file

@ -43,7 +43,7 @@ pub fn main() {
fail_unless!(transform(Some(10)) == Some(~"11")); fail_unless!(transform(Some(10)) == Some(~"11"));
fail_unless!(transform(None) == None); fail_unless!(transform(None) == None);
fail_unless!((~[~"hi"]) fail_unless!((~[~"hi"])
.bind(|x| ~[copy *x, *x + ~"!"] ) .bind(|x| ~[x.clone(), *x + ~"!"] )
.bind(|x| ~[copy *x, *x + ~"?"] ) == .bind(|x| ~[x.clone(), *x + ~"?"] ) ==
~[~"hi", ~"hi?", ~"hi!", ~"hi!?"]); ~[~"hi", ~"hi?", ~"hi!", ~"hi!?"]);
} }

View file

@ -5,7 +5,7 @@
pub fn main() { pub fn main() {
let y = ~3; let y = ~3;
let foo: @fn(&int) -> int = { let foo: @fn(&int) -> int = {
let y = copy y; let y = y.clone();
|x| *x + *y |x| *x + *y
}; };
fail_unless!(foo(@22) == 25); fail_unless!(foo(@22) == 25);

View file

@ -19,6 +19,6 @@ struct X { foo: ~str, bar: ~str }
pub fn main() { pub fn main() {
let x = X {foo: ~"hello", bar: ~"world"}; let x = X {foo: ~"hello", bar: ~"world"};
debug!(copy x.foo); debug!(x.foo.clone());
debug!(copy x.bar); debug!(x.bar.clone());
} }

View file

@ -647,10 +647,10 @@ pub fn main() {
let v = @v as @TyVisitor; let v = @v as @TyVisitor;
visit_tydesc(td, v); visit_tydesc(td, v);
for (copy u.vals).each |s| { for (u.vals.clone()).each |s| {
io::println(fmt!("val: %s", *s)); io::println(fmt!("val: %s", *s));
} }
error!("%?", copy u.vals); error!("%?", u.vals.clone());
fail_unless!(u.vals == ~[ fail_unless!(u.vals == ~[
~"1", ~"2", ~"3", ~"true", ~"false", ~"5", ~"4", ~"3", ~"12" ~"1", ~"2", ~"3", ~"true", ~"false", ~"5", ~"4", ~"3", ~"12"
]); ]);

View file

@ -150,7 +150,7 @@ pub fn main() {
visit_ty::<i16>(vv); visit_ty::<i16>(vv);
visit_ty::<~[int]>(vv); visit_ty::<~[int]>(vv);
for (copy v.types).each {|s| for (v.types.clone()).each {|s|
io::println(fmt!("type: %s", s)); io::println(fmt!("type: %s", s));
} }
fail_unless!(v.types == ["bool", "int", "i8", "i16", fail_unless!(v.types == ["bool", "int", "i8", "i16",

View file

@ -20,9 +20,9 @@ fn iter<T>(v: ~[T], it: &fn(&T) -> bool) {
} }
} }
fn find_pos<T:Eq + Copy>(n: T, h: ~[T]) -> Option<uint> { fn find_pos<T:Eq + Copy + Clone>(n: T, h: ~[T]) -> Option<uint> {
let mut i = 0u; let mut i = 0u;
for iter(copy h) |e| { for iter(h.clone()) |e| {
if *e == n { return Some(i); } if *e == n { return Some(i); }
i += 1u; i += 1u;
} }
@ -31,8 +31,8 @@ fn find_pos<T:Eq + Copy>(n: T, h: ~[T]) -> Option<uint> {
fn bail_deep(x: ~[~[bool]]) { fn bail_deep(x: ~[~[bool]]) {
let mut seen = false; let mut seen = false;
for iter(copy x) |x| { for iter(x.clone()) |x| {
for iter(copy *x) |x| { for iter(x.clone()) |x| {
fail_unless!(!seen); fail_unless!(!seen);
if *x { seen = true; return; } if *x { seen = true; return; }
} }

View file

@ -20,7 +20,7 @@ pub fn main() {
{ {
match io::file_writer(&path, [io::Create, io::Truncate]) { match io::file_writer(&path, [io::Create, io::Truncate]) {
Err(copy e) => fail!(e), Err(ref e) => fail!(e.clone()),
Ok(f) => { Ok(f) => {
for uint::range(0, 1000) |_i| { for uint::range(0, 1000) |_i| {
f.write_u8(0); f.write_u8(0);

View file

@ -16,7 +16,7 @@ extern mod std;
fn test1() { fn test1() {
let mut s: ~str = ~"hello"; let mut s: ~str = ~"hello";
s += ~"world"; s += ~"world";
debug!(copy s); debug!(s.clone());
fail_unless!((s[9] == 'd' as u8)); fail_unless!((s[9] == 'd' as u8));
} }
@ -26,8 +26,8 @@ fn test2() {
let ff: ~str = ~"abc"; let ff: ~str = ~"abc";
let a: ~str = ff + ~"ABC" + ff; let a: ~str = ff + ~"ABC" + ff;
let b: ~str = ~"ABC" + ff + ~"ABC"; let b: ~str = ~"ABC" + ff + ~"ABC";
debug!(copy a); debug!(a.clone());
debug!(copy b); debug!(b.clone());
fail_unless!((a == ~"abcABCabc")); fail_unless!((a == ~"abcABCabc"));
fail_unless!((b == ~"ABCabcABC")); fail_unless!((b == ~"ABCabcABC"));
} }

View file

@ -16,6 +16,6 @@ pub fn main() {
let a: ~str = ~"hello"; let a: ~str = ~"hello";
let b: ~str = ~"world"; let b: ~str = ~"world";
let s: ~str = a + b; let s: ~str = a + b;
debug!(copy s); debug!(s.clone());
fail_unless!((s[9] == 'd' as u8)); fail_unless!((s[9] == 'd' as u8));
} }

View file

@ -11,8 +11,8 @@
extern mod std; extern mod std;
fn test(actual: ~str, expected: ~str) { fn test(actual: ~str, expected: ~str) {
debug!(copy actual); debug!(actual.clone());
debug!(copy expected); debug!(expected.clone());
fail_unless!((actual == expected)); fail_unless!((actual == expected));
} }

View file

@ -17,7 +17,7 @@ impl to_str for int {
fn to_str(&self) -> ~str { int::to_str(*self) } fn to_str(&self) -> ~str { int::to_str(*self) }
} }
impl to_str for ~str { impl to_str for ~str {
fn to_str(&self) -> ~str { copy *self } fn to_str(&self) -> ~str { self.clone() }
} }
impl to_str for () { impl to_str for () {
fn to_str(&self) -> ~str { ~"()" } fn to_str(&self) -> ~str { ~"()" }

View file

@ -12,7 +12,7 @@ pub fn main() {
let mut i = ~1; let mut i = ~1;
// Should be a copy // Should be a copy
let mut j; let mut j;
j = copy i; j = i.clone();
*i = 2; *i = 2;
*j = 3; *j = 3;
fail_unless!(*i == 2); fail_unless!(*i == 2);

View file

@ -11,7 +11,7 @@
pub fn main() { pub fn main() {
let mut i = ~1; let mut i = ~1;
// Should be a copy // Should be a copy
let mut j = copy i; let mut j = i.clone();
*i = 2; *i = 2;
*j = 3; *j = 3;
fail_unless!(*i == 2); fail_unless!(*i == 2);

View file

@ -10,7 +10,7 @@
pub fn main() { pub fn main() {
let mut a = ~[~10]; let mut a = ~[~10];
let b = copy a; let b = a.clone();
fail_unless!(*a[0] == 10); fail_unless!(*a[0] == 10);
fail_unless!(*b[0] == 10); fail_unless!(*b[0] == 10);

View file

@ -10,6 +10,6 @@
pub fn main() { pub fn main() {
let a = ~[1, 2, 3, 4, 5]; let a = ~[1, 2, 3, 4, 5];
let mut b = ~[copy a, copy a]; let mut b = ~[a.clone(), a.clone()];
b = b + b; // FIXME(#3387)---can't write b += b b = b + b; // FIXME(#3387)---can't write b += b
} }

View file

@ -1,4 +1,4 @@
fn foldl<T, U: Copy>( fn foldl<T, U: Copy+Clone>(
values: &[T], values: &[T],
initial: U, initial: U,
function: &fn(partial: U, element: &T) -> U function: &fn(partial: U, element: &T) -> U
@ -6,11 +6,11 @@ fn foldl<T, U: Copy>(
match values { match values {
[head, ..tail] => [head, ..tail] =>
foldl(tail, function(initial, &head), function), foldl(tail, function(initial, &head), function),
[] => copy initial [] => initial.clone()
} }
} }
fn foldr<T, U: Copy>( fn foldr<T, U: Copy+Clone>(
values: &[T], values: &[T],
initial: U, initial: U,
function: &fn(element: &T, partial: U) -> U function: &fn(element: &T, partial: U) -> U
@ -18,7 +18,7 @@ fn foldr<T, U: Copy>(
match values { match values {
[..head, tail] => [..head, tail] =>
foldr(head, function(&tail, initial), function), foldr(head, function(&tail, initial), function),
[] => copy initial [] => initial.clone()
} }
} }