Skip to content

Commit 438893b

Browse files
committed
Removed DeepClone. Issue #12698.
1 parent 96e8c00 commit 438893b

28 files changed

+36
-367
lines changed

src/libstd/cell.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! Types dealing with dynamic mutability
1212
1313
use cast;
14-
use clone::{Clone, DeepClone};
14+
use clone::Clone;
1515
use cmp::Eq;
1616
use fmt;
1717
use kinds::{marker, Pod};
@@ -222,13 +222,6 @@ impl<T: Clone> Clone for RefCell<T> {
222222
}
223223
}
224224

225-
impl<T: DeepClone> DeepClone for RefCell<T> {
226-
fn deep_clone(&self) -> RefCell<T> {
227-
let x = self.borrow();
228-
RefCell::new(x.get().deep_clone())
229-
}
230-
}
231-
232225
impl<T: Eq> Eq for RefCell<T> {
233226
fn eq(&self, other: &RefCell<T>) -> bool {
234227
let a = self.borrow();

src/libstd/clone.rs

-100
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ the `clone` method.
2121
2222
*/
2323

24-
use std::kinds::Freeze;
25-
2624
/// A common trait for cloning an object.
2725
pub trait Clone {
2826
/// Returns a copy of the value. The contents of owned pointers
@@ -125,92 +123,6 @@ extern_fn_clone!(A, B, C, D, E, F)
125123
extern_fn_clone!(A, B, C, D, E, F, G)
126124
extern_fn_clone!(A, B, C, D, E, F, G, H)
127125

128-
/// A trait distinct from `Clone` which represents "deep copies" of things like
129-
/// managed boxes which would otherwise not be copied.
130-
pub trait DeepClone: Clone {
131-
/// Return a deep copy of the value. Unlike `Clone`, the contents of shared pointer types
132-
/// *are* copied.
133-
fn deep_clone(&self) -> Self;
134-
135-
/// Perform deep copy-assignment from `source`.
136-
///
137-
/// `a.deep_clone_from(&b)` is equivalent to `a = b.deep_clone()` in
138-
/// functionality, but can be overridden to reuse the resources of `a` to
139-
/// avoid unnecessary allocations.
140-
#[inline(always)]
141-
fn deep_clone_from(&mut self, source: &Self) {
142-
*self = source.deep_clone()
143-
}
144-
}
145-
146-
impl<T: DeepClone> DeepClone for ~T {
147-
/// Return a deep copy of the owned box.
148-
#[inline]
149-
fn deep_clone(&self) -> ~T { ~(**self).deep_clone() }
150-
151-
/// Perform deep copy-assignment from `source` by reusing the existing allocation.
152-
fn deep_clone_from(&mut self, source: &~T) {
153-
**self = (**source).deep_clone()
154-
}
155-
}
156-
157-
// FIXME: #6525: should also be implemented for `T: Send + DeepClone`
158-
impl<T: Freeze + DeepClone + 'static> DeepClone for @T {
159-
/// Return a deep copy of the managed box. The `Freeze` trait is required to prevent performing
160-
/// a deep clone of a potentially cyclical type.
161-
#[inline]
162-
fn deep_clone(&self) -> @T { @(**self).deep_clone() }
163-
}
164-
165-
macro_rules! deep_clone_impl(
166-
($t:ty) => {
167-
impl DeepClone for $t {
168-
/// Return a deep copy of the value.
169-
#[inline]
170-
fn deep_clone(&self) -> $t { *self }
171-
}
172-
}
173-
)
174-
175-
deep_clone_impl!(int)
176-
deep_clone_impl!(i8)
177-
deep_clone_impl!(i16)
178-
deep_clone_impl!(i32)
179-
deep_clone_impl!(i64)
180-
181-
deep_clone_impl!(uint)
182-
deep_clone_impl!(u8)
183-
deep_clone_impl!(u16)
184-
deep_clone_impl!(u32)
185-
deep_clone_impl!(u64)
186-
187-
deep_clone_impl!(f32)
188-
deep_clone_impl!(f64)
189-
190-
deep_clone_impl!(())
191-
deep_clone_impl!(bool)
192-
deep_clone_impl!(char)
193-
194-
macro_rules! extern_fn_deep_clone(
195-
($($A:ident),*) => (
196-
impl<$($A,)* ReturnType> DeepClone for extern "Rust" fn($($A),*) -> ReturnType {
197-
/// Return a copy of a function pointer
198-
#[inline]
199-
fn deep_clone(&self) -> extern "Rust" fn($($A),*) -> ReturnType { *self }
200-
}
201-
)
202-
)
203-
204-
extern_fn_deep_clone!()
205-
extern_fn_deep_clone!(A)
206-
extern_fn_deep_clone!(A, B)
207-
extern_fn_deep_clone!(A, B, C)
208-
extern_fn_deep_clone!(A, B, C, D)
209-
extern_fn_deep_clone!(A, B, C, D, E)
210-
extern_fn_deep_clone!(A, B, C, D, E, F)
211-
extern_fn_deep_clone!(A, B, C, D, E, F, G)
212-
extern_fn_deep_clone!(A, B, C, D, E, F, G, H)
213-
214126
#[test]
215127
fn test_owned_clone() {
216128
let a = ~5i;
@@ -241,14 +153,6 @@ fn test_clone_from() {
241153
assert_eq!(*b, 5);
242154
}
243155

244-
#[test]
245-
fn test_deep_clone_from() {
246-
let a = ~5;
247-
let mut b = ~10;
248-
b.deep_clone_from(&a);
249-
assert_eq!(*b, 5);
250-
}
251-
252156
#[test]
253157
fn test_extern_fn_clone() {
254158
trait Empty {}
@@ -261,8 +165,4 @@ fn test_extern_fn_clone() {
261165
let _ = test_fn_a.clone();
262166
let _ = test_fn_b::<int>.clone();
263167
let _ = test_fn_c.clone();
264-
265-
let _ = test_fn_a.deep_clone();
266-
let _ = test_fn_b::<int>.deep_clone();
267-
let _ = test_fn_c.deep_clone();
268168
}

src/libstd/gc.rs

+1-22
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ collector is task-local so `Gc<T>` is not sendable.
1919
#[allow(experimental)];
2020

2121
use kinds::marker;
22-
use kinds::Send;
23-
use clone::{Clone, DeepClone};
22+
use clone::Clone;
2423
use managed;
2524

2625
/// Immutable garbage-collected pointer type
@@ -78,16 +77,6 @@ pub static GC: () = ();
7877
#[cfg(test)]
7978
pub static GC: () = ();
8079

81-
/// The `Send` bound restricts this to acyclic graphs where it is well-defined.
82-
///
83-
/// A `Freeze` bound would also work, but `Send` *or* `Freeze` cannot be expressed.
84-
impl<T: DeepClone + Send + 'static> DeepClone for Gc<T> {
85-
#[inline]
86-
fn deep_clone(&self) -> Gc<T> {
87-
Gc::new(self.borrow().deep_clone())
88-
}
89-
}
90-
9180
#[cfg(test)]
9281
mod tests {
9382
use prelude::*;
@@ -104,16 +93,6 @@ mod tests {
10493
assert_eq!(y.borrow().with(|x| *x), 20);
10594
}
10695

107-
#[test]
108-
fn test_deep_clone() {
109-
let x = Gc::new(RefCell::new(5));
110-
let y = x.deep_clone();
111-
x.borrow().with_mut(|inner| {
112-
*inner = 20;
113-
});
114-
assert_eq!(y.borrow().with(|x| *x), 5);
115-
}
116-
11796
#[test]
11897
fn test_simple() {
11998
let x = Gc::new(5);

src/libstd/iter.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ impl<'a,
17571757

17581758
/// An iterator that yields `None` forever after the underlying iterator
17591759
/// yields `None` once.
1760-
#[deriving(Clone, DeepClone)]
1760+
#[deriving(Clone)]
17611761
pub struct Fuse<T> {
17621762
priv iter: T,
17631763
priv done: bool
@@ -1946,7 +1946,7 @@ impl<A: Add<A, A> + Clone> Iterator<A> for Counter<A> {
19461946
}
19471947

19481948
/// An iterator over the range [start, stop)
1949-
#[deriving(Clone, DeepClone)]
1949+
#[deriving(Clone)]
19501950
pub struct Range<A> {
19511951
priv state: A,
19521952
priv stop: A,
@@ -2020,7 +2020,7 @@ impl<A: Int + Ord + Clone + ToPrimitive> DoubleEndedIterator<A> for Range<A> {
20202020
}
20212021

20222022
/// An iterator over the range [start, stop]
2023-
#[deriving(Clone, DeepClone)]
2023+
#[deriving(Clone)]
20242024
pub struct RangeInclusive<A> {
20252025
priv range: Range<A>,
20262026
priv done: bool
@@ -2083,7 +2083,7 @@ impl<A: Sub<A, A> + Int + Ord + Clone + ToPrimitive> DoubleEndedIterator<A>
20832083
}
20842084

20852085
/// An iterator over the range [start, stop) by `step`. It handles overflow by stopping.
2086-
#[deriving(Clone, DeepClone)]
2086+
#[deriving(Clone)]
20872087
pub struct RangeStep<A> {
20882088
priv state: A,
20892089
priv stop: A,
@@ -2115,7 +2115,7 @@ impl<A: CheckedAdd + Ord + Clone> Iterator<A> for RangeStep<A> {
21152115
}
21162116

21172117
/// An iterator over the range [start, stop] by `step`. It handles overflow by stopping.
2118-
#[deriving(Clone, DeepClone)]
2118+
#[deriving(Clone)]
21192119
pub struct RangeStepInclusive<A> {
21202120
priv state: A,
21212121
priv stop: A,
@@ -2150,7 +2150,7 @@ impl<A: CheckedAdd + Ord + Clone + Eq> Iterator<A> for RangeStepInclusive<A> {
21502150
}
21512151

21522152
/// An iterator that repeats an element endlessly
2153-
#[deriving(Clone, DeepClone)]
2153+
#[deriving(Clone)]
21542154
pub struct Repeat<A> {
21552155
priv element: A
21562156
}

src/libstd/num/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
#[allow(missing_doc)];
1717

18-
use clone::{Clone, DeepClone};
18+
use clone::Clone;
1919
use cmp::{Eq, Ord};
2020
use kinds::Pod;
2121
use mem::size_of;
@@ -247,7 +247,6 @@ pub trait Bitwise: Bounded
247247
/// may be useful for systems programming.
248248
pub trait Primitive: Pod
249249
+ Clone
250-
+ DeepClone
251250
+ Num
252251
+ NumCast
253252
+ Ord

src/libstd/option.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,15 @@
3939
4040
use any::Any;
4141
use clone::Clone;
42-
use clone::DeepClone;
43-
use cmp::{Eq, TotalOrd};
42+
use cmp::{Eq, TotalEq, TotalOrd};
4443
use default::Default;
4544
use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSize};
4645
use kinds::Send;
4746
use mem;
4847
use vec;
4948

5049
/// The option type
51-
#[deriving(Clone, DeepClone, Eq, Ord, TotalEq, TotalOrd, Show)]
50+
#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd, Show)]
5251
pub enum Option<T> {
5352
/// No value
5453
None,
@@ -387,7 +386,7 @@ impl<T> Default for Option<T> {
387386
/////////////////////////////////////////////////////////////////////////////
388387

389388
/// An iterator that yields either one or zero elements
390-
#[deriving(Clone, DeepClone)]
389+
#[deriving(Clone)]
391390
pub struct Item<A> {
392391
priv opt: Option<A>
393392
}

src/libstd/path/posix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub type RevStrComponents<'a> = Map<'a, &'a [u8], Option<&'a str>,
3838
RevComponents<'a>>;
3939

4040
/// Represents a POSIX file path
41-
#[deriving(Clone, DeepClone)]
41+
#[deriving(Clone)]
4242
pub struct Path {
4343
priv repr: ~[u8], // assumed to never be empty or contain NULs
4444
priv sepidx: Option<uint> // index of the final separator in repr

src/libstd/path/windows.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub type RevComponents<'a> = Map<'a, Option<&'a str>, &'a [u8],
7979
//
8080
// The only error condition imposed here is valid utf-8. All other invalid paths are simply
8181
// preserved by the data structure; let the Windows API error out on them.
82-
#[deriving(Clone, DeepClone)]
82+
#[deriving(Clone)]
8383
pub struct Path {
8484
priv repr: ~str, // assumed to never be empty
8585
priv prefix: Option<PathPrefix>,
@@ -942,7 +942,7 @@ pub fn is_sep_byte_verbatim(u: &u8) -> bool {
942942
}
943943

944944
/// Prefix types for Path
945-
#[deriving(Eq, Clone, DeepClone)]
945+
#[deriving(Eq, Clone)]
946946
pub enum PathPrefix {
947947
/// Prefix `\\?\`, uint is the length of the following component
948948
VerbatimPrefix(uint),

src/libstd/prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub use mem::drop;
3838
pub use ascii::{Ascii, AsciiCast, OwnedAsciiCast, AsciiStr, IntoBytes};
3939
pub use c_str::ToCStr;
4040
pub use char::Char;
41-
pub use clone::{Clone, DeepClone};
41+
pub use clone::Clone;
4242
pub use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater, Equiv};
4343
pub use container::{Container, Mutable, Map, MutableMap, Set, MutableSet};
4444
pub use iter::{FromIterator, Extendable};

src/libstd/rc.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pointers, and then storing the parent pointers as `Weak` pointers.
2424
*/
2525

2626
use cast::transmute;
27-
use clone::{Clone, DeepClone};
27+
use clone::Clone;
2828
use cmp::{Eq, Ord};
2929
use kinds::marker;
3030
use ops::{Deref, Drop};
@@ -118,13 +118,6 @@ impl<T> Clone for Rc<T> {
118118
}
119119
}
120120

121-
impl<T: DeepClone> DeepClone for Rc<T> {
122-
#[inline]
123-
fn deep_clone(&self) -> Rc<T> {
124-
Rc::new(self.borrow().deep_clone())
125-
}
126-
}
127-
128121
impl<T: Eq> Eq for Rc<T> {
129122
#[inline(always)]
130123
fn eq(&self, other: &Rc<T>) -> bool { *self.borrow() == *other.borrow() }
@@ -210,16 +203,6 @@ mod tests {
210203
assert_eq!(y.borrow().with(|v| *v), 20);
211204
}
212205

213-
#[test]
214-
fn test_deep_clone() {
215-
let x = Rc::new(RefCell::new(5));
216-
let y = x.deep_clone();
217-
x.borrow().with_mut(|inner| {
218-
*inner = 20;
219-
});
220-
assert_eq!(y.borrow().with(|v| *v), 5);
221-
}
222-
223206
#[test]
224207
fn test_simple() {
225208
let x = Rc::new(5);

src/libstd/result.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use iter::{Iterator, FromIterator};
1616
use option::{None, Option, Some};
1717

1818
/// `Result` is a type that represents either success (`Ok`) or failure (`Err`).
19-
#[deriving(Clone, DeepClone, Eq, Ord, TotalEq, TotalOrd, Show)]
19+
#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd, Show)]
2020
#[must_use]
2121
pub enum Result<T, E> {
2222
/// Contains the success value

0 commit comments

Comments
 (0)