Skip to content

Commit 6f1e8ef

Browse files
committed
auto merge of #5404 : bstrie/rust/decopy, r=pcwalton
Also turn `copy` into `.clone()` in much of run-pass.
2 parents 5a77a10 + ee58424 commit 6f1e8ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+115
-86
lines changed

src/libcore/clone.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ impl Clone for () {
2020
fn clone(&self) -> () { () }
2121
}
2222

23+
impl<T:Clone> Clone for ~T {
24+
#[inline(always)]
25+
fn clone(&self) -> ~T { ~(**self).clone() }
26+
}
27+
2328
macro_rules! clone_impl(
2429
($t:ty) => {
2530
impl Clone for $t {

src/libcore/str.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use at_vec;
2121
use cast;
2222
use char;
23+
use clone::Clone;
2324
use cmp::{Equiv, TotalOrd, Ordering, Less, Equal, Greater};
2425
use libc;
2526
use option::{None, Option, Some};
@@ -2436,6 +2437,13 @@ impl OwnedStr for ~str {
24362437
}
24372438
}
24382439
2440+
impl Clone for ~str {
2441+
#[inline(always)]
2442+
fn clone(&self) -> ~str {
2443+
self.to_str() // hilarious
2444+
}
2445+
}
2446+
24392447
#[cfg(test)]
24402448
mod tests {
24412449
use char;

src/libcore/unstable/global.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ unsafe fn global_data_clone_create_<T:Owned + Clone>(
6868
match value {
6969
None => {
7070
let value = create();
71-
clone_value = Some(value.clone());
71+
clone_value = Some((*value).clone());
7272
Some(value)
7373
}
7474
Some(value) => {
75-
clone_value = Some(value.clone());
75+
clone_value = Some((*value).clone());
7676
Some(value)
7777
}
7878
}
@@ -193,7 +193,7 @@ fn get_global_state() -> Exclusive<GlobalState> {
193193
// Successfully installed the global pointer
194194

195195
// Take a handle to return
196-
let clone = state.clone();
196+
let clone = (*state).clone();
197197

198198
// Install a runtime exit function to destroy the global object
199199
do at_exit {

src/libcore/vec.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use container::{Container, Mutable};
1616
use cast;
1717
use cmp::{Eq, Equiv, Ord, TotalOrd, Ordering, Less, Equal, Greater};
18+
use clone::Clone;
1819
use iter::BaseIter;
1920
use iter;
2021
use kinds::Copy;
@@ -2501,6 +2502,18 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for @[A] {
25012502
}
25022503
}
25032504

2505+
impl<A:Clone> Clone for ~[A] {
2506+
#[inline]
2507+
fn clone(&self) -> ~[A] {
2508+
let mut dolly = ~[];
2509+
vec::reserve(&mut dolly, self.len());
2510+
for self.each |item| {
2511+
dolly.push(item.clone());
2512+
}
2513+
return dolly;
2514+
}
2515+
}
2516+
25042517
// ___________________________________________________________________________
25052518

25062519
#[cfg(test)]

src/libstd/arc.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ mod tests {
572572
#[test] #[should_fail] #[ignore(cfg(windows))]
573573
pub fn test_rw_arc_poison_wr() {
574574
let arc = ~RWARC(1);
575-
let arc2 = ~arc.clone();
575+
let arc2 = (*arc).clone();
576576
do task::try || {
577577
do arc2.write |one| {
578578
fail_unless!(*one == 2);
@@ -585,7 +585,7 @@ mod tests {
585585
#[test] #[should_fail] #[ignore(cfg(windows))]
586586
pub fn test_rw_arc_poison_ww() {
587587
let arc = ~RWARC(1);
588-
let arc2 = ~arc.clone();
588+
let arc2 = (*arc).clone();
589589
do task::try || {
590590
do arc2.write |one| {
591591
fail_unless!(*one == 2);
@@ -598,7 +598,7 @@ mod tests {
598598
#[test] #[should_fail] #[ignore(cfg(windows))]
599599
pub fn test_rw_arc_poison_dw() {
600600
let arc = ~RWARC(1);
601-
let arc2 = ~arc.clone();
601+
let arc2 = (*arc).clone();
602602
do task::try || {
603603
do arc2.write_downgrade |write_mode| {
604604
do (&write_mode).write |one| {
@@ -613,7 +613,7 @@ mod tests {
613613
#[test] #[ignore(cfg(windows))]
614614
pub fn test_rw_arc_no_poison_rr() {
615615
let arc = ~RWARC(1);
616-
let arc2 = ~arc.clone();
616+
let arc2 = (*arc).clone();
617617
do task::try || {
618618
do arc2.read |one| {
619619
fail_unless!(*one == 2);
@@ -626,7 +626,7 @@ mod tests {
626626
#[test] #[ignore(cfg(windows))]
627627
pub fn test_rw_arc_no_poison_rw() {
628628
let arc = ~RWARC(1);
629-
let arc2 = ~arc.clone();
629+
let arc2 = (*arc).clone();
630630
do task::try || {
631631
do arc2.read |one| {
632632
fail_unless!(*one == 2);
@@ -639,7 +639,7 @@ mod tests {
639639
#[test] #[ignore(cfg(windows))]
640640
pub fn test_rw_arc_no_poison_dr() {
641641
let arc = ~RWARC(1);
642-
let arc2 = ~arc.clone();
642+
let arc2 = (*arc).clone();
643643
do task::try || {
644644
do arc2.write_downgrade |write_mode| {
645645
let read_mode = arc2.downgrade(write_mode);
@@ -655,7 +655,7 @@ mod tests {
655655
#[test]
656656
pub fn test_rw_arc() {
657657
let arc = ~RWARC(0);
658-
let arc2 = ~arc.clone();
658+
let arc2 = (*arc).clone();
659659
let (p,c) = comm::stream();
660660

661661
do task::spawn || {
@@ -673,7 +673,7 @@ mod tests {
673673
// Readers try to catch the writer in the act
674674
let mut children = ~[];
675675
for 5.times {
676-
let arc3 = ~arc.clone();
676+
let arc3 = (*arc).clone();
677677
do task::task().future_result(|+r| children.push(r)).spawn
678678
|| {
679679
do arc3.read |num| {
@@ -704,7 +704,7 @@ mod tests {
704704
for 10.times {
705705
let ((rp1,rc1),(rp2,rc2)) = (comm::stream(),comm::stream());
706706
reader_convos.push((rc1, rp2));
707-
let arcn = ~arc.clone();
707+
let arcn = (*arc).clone();
708708
do task::spawn || {
709709
rp1.recv(); // wait for downgrader to give go-ahead
710710
do arcn.read |state| {
@@ -715,7 +715,7 @@ mod tests {
715715
}
716716

717717
// Writer task
718-
let arc2 = ~arc.clone();
718+
let arc2 = (*arc).clone();
719719
let ((wp1,wc1),(wp2,wc2)) = (comm::stream(),comm::stream());
720720
do task::spawn || {
721721
wp1.recv();

src/libstd/sync.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ mod tests {
827827
// "load tmp = move ptr; inc tmp; store ptr <- tmp" dance.
828828
let (p,c) = comm::stream();
829829
let m = ~Mutex();
830-
let m2 = ~m.clone();
830+
let m2 = m.clone();
831831
let mut sharedstate = ~0;
832832
let ptr = ptr::addr_of(&(*sharedstate));
833833
do task::spawn || {
@@ -1105,13 +1105,13 @@ mod tests {
11051105
// Test mutual exclusion between readers and writers. Just like the
11061106
// mutex mutual exclusion test, a ways above.
11071107
let (p,c) = comm::stream();
1108-
let x2 = ~x.clone();
1108+
let x2 = (*x).clone();
11091109
let mut sharedstate = ~0;
11101110
let ptr = ptr::addr_of(&(*sharedstate));
11111111
do task::spawn || {
11121112
let sharedstate: &mut int =
11131113
unsafe { cast::reinterpret_cast(&ptr) };
1114-
access_shared(sharedstate, x2, mode1, 10);
1114+
access_shared(sharedstate, &x2, mode1, 10);
11151115
c.send(());
11161116
}
11171117
access_shared(sharedstate, x, mode2, 10);
@@ -1150,14 +1150,14 @@ mod tests {
11501150
mode2: RWlockMode,
11511151
make_mode2_go_first: bool) {
11521152
// Much like sem_multi_resource.
1153-
let x2 = ~x.clone();
1153+
let x2 = (*x).clone();
11541154
let (p1,c1) = comm::stream();
11551155
let (p2,c2) = comm::stream();
11561156
do task::spawn || {
11571157
if !make_mode2_go_first {
11581158
let _ = p2.recv(); // parent sends to us once it locks, or ...
11591159
}
1160-
do lock_rwlock_in_mode(x2, mode2) {
1160+
do lock_rwlock_in_mode(&x2, mode2) {
11611161
if make_mode2_go_first {
11621162
c1.send(()); // ... we send to it once we lock
11631163
}
@@ -1207,7 +1207,7 @@ mod tests {
12071207
12081208
// Child wakes up parent
12091209
do x.write_cond |cond| {
1210-
let x2 = ~x.clone();
1210+
let x2 = (*x).clone();
12111211
do task::spawn || {
12121212
do x2.write_cond |cond| {
12131213
let woken = cond.signal();
@@ -1218,7 +1218,7 @@ mod tests {
12181218
}
12191219
// Parent wakes up child
12201220
let (port,chan) = comm::stream();
1221-
let x3 = ~x.clone();
1221+
let x3 = (*x).clone();
12221222
do task::spawn || {
12231223
do x3.write_cond |cond| {
12241224
chan.send(());
@@ -1253,11 +1253,11 @@ mod tests {
12531253
let mut ports = ~[];
12541254
12551255
for num_waiters.times {
1256-
let xi = ~x.clone();
1256+
let xi = (*x).clone();
12571257
let (port, chan) = comm::stream();
12581258
ports.push(port);
12591259
do task::spawn || {
1260-
do lock_cond(xi, dg1) |cond| {
1260+
do lock_cond(&xi, dg1) |cond| {
12611261
chan.send(());
12621262
cond.wait();
12631263
chan.send(());
@@ -1289,10 +1289,10 @@ mod tests {
12891289
pub fn rwlock_kill_helper(mode1: RWlockMode, mode2: RWlockMode) {
12901290
// Mutex must get automatically unlocked if failed/killed within.
12911291
let x = ~RWlock();
1292-
let x2 = ~x.clone();
1292+
let x2 = (*x).clone();
12931293
12941294
let result: result::Result<(),()> = do task::try || {
1295-
do lock_rwlock_in_mode(x2, mode1) {
1295+
do lock_rwlock_in_mode(&x2, mode1) {
12961296
fail!();
12971297
}
12981298
};

src/libsyntax/ext/pipes/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn analyze(proto: protocol, _cx: @ext_ctxt) {
6363
debug!("colive iteration %?", i);
6464
let mut new_colive = ~[];
6565
for colive.eachi |i, this_colive| {
66-
let mut result = ~this_colive.clone();
66+
let mut result = this_colive.clone();
6767
let this = proto.get_state_by_id(i);
6868
for this_colive.ones |j| {
6969
let next = proto.get_state_by_id(j);

src/test/run-pass/alt-value-binding-in-guard-3291.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
fn foo(x: Option<~int>, b: bool) -> int {
1212
match x {
1313
None => { 1 }
14-
Some(copy x) if b => { *x }
14+
Some(ref x) if b => { *x.clone() }
1515
Some(_) => { 0 }
1616
}
1717
}

src/test/run-pass/assignability-trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn main() {
4343
// Call a method
4444
for x.iterate() |y| { fail_unless!(x[*y] == *y); }
4545
// Call a parameterized function
46-
fail_unless!(length(copy x) == vec::len(x));
46+
fail_unless!(length(x.clone()) == vec::len(x));
4747
// Call a parameterized function, with type arguments that require
4848
// a borrow
4949
fail_unless!(length::<int, &[int]>(x) == vec::len(x));

src/test/run-pass/block-iter-2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ fn iter_vec<T>(v: ~[T], f: &fn(&T)) { for v.each |x| { f(x); } }
1515
pub fn main() {
1616
let v = ~[1, 2, 3, 4, 5];
1717
let mut sum = 0;
18-
iter_vec(copy v, |i| {
19-
iter_vec(copy v, |j| {
18+
iter_vec(v.clone(), |i| {
19+
iter_vec(v.clone(), |j| {
2020
sum += *i * *j;
2121
});
2222
});

src/test/run-pass/block-vec-map2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ pub fn main() {
1515
vec::map2(~[1, 2, 3, 4, 5],
1616
~[true, false, false, true, true],
1717
|i, b| if *b { -(*i) } else { *i } );
18-
error!(copy v);
18+
error!(v.clone());
1919
fail_unless!((v == ~[-1, 2, 3, -4, -5]));
2020
}

src/test/run-pass/borrowck-borrow-from-expr-block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn borrow(x: &int, f: &fn(x: &int)) {
1313
}
1414

1515
fn test1(x: @~int) {
16-
do borrow(copy *x) |p| {
16+
do borrow(&*x.clone()) |p| {
1717
let x_a = ptr::addr_of(&(**x));
1818
fail_unless!((x_a as uint) != ptr::to_uint(p));
1919
fail_unless!(unsafe{*x_a} == *p);

src/test/run-pass/borrowck-preserve-box-sometimes-needed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
fn switcher(x: Option<@int>) {
1414
let mut x = x;
1515
match x {
16-
Some(@y) => { copy y; x = None; }
16+
Some(@y) => { y.clone(); x = None; }
1717
None => { }
1818
}
1919
}

src/test/run-pass/class-exports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod kitty {
2222
}
2323

2424
pub impl cat {
25-
fn get_name(&self) -> ~str { copy self.name }
25+
fn get_name(&self) -> ~str { self.name.clone() }
2626
}
2727

2828
pub fn cat(in_name: ~str) -> cat {

src/test/run-pass/class-implement-traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
5353
cat {
5454
meows: in_x,
5555
how_hungry: in_y,
56-
name: copy in_name
56+
name: in_name.clone()
5757
}
5858
}
5959

src/test/run-pass/class-separate-impl.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// except according to those terms.
1010

1111
// xfail-fast
12-
use core::to_str::*;
13-
1412
struct cat {
1513
priv meows : uint,
1614

@@ -53,7 +51,12 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
5351
}
5452

5553
impl ToStr for cat {
56-
pure fn to_str(&self) -> ~str { copy self.name }
54+
pure fn to_str(&self) -> ~str {
55+
// FIXME #5384: this unsafe block is to work around purity
56+
unsafe {
57+
self.name.clone()
58+
}
59+
}
5760
}
5861

5962
fn print_out(thing: @ToStr, expected: ~str) {

src/test/run-pass/expr-alt-generic-unique1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
// -*- rust -*-
1414
type compare<T> = @fn(~T, ~T) -> bool;
1515

16-
fn test_generic<T:Copy>(expected: ~T, eq: compare<T>) {
16+
fn test_generic<T:Copy+Clone>(expected: ~T, eq: compare<T>) {
1717
let actual: ~T = match true {
18-
true => { copy expected },
18+
true => { expected.clone() },
1919
_ => fail!(~"wat")
2020
};
2121
fail_unless!((eq(expected, actual)));

src/test/run-pass/expr-alt-generic-unique2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
type compare<T> = @fn(T, T) -> bool;
1515

16-
fn test_generic<T:Copy>(expected: T, eq: compare<T>) {
16+
fn test_generic<T:Copy+Clone>(expected: T, eq: compare<T>) {
1717
let actual: T = match true {
18-
true => copy expected,
18+
true => expected.clone(),
1919
_ => fail!(~"wat")
2020
};
2121
fail_unless!((eq(expected, actual)));

0 commit comments

Comments
 (0)