Skip to content

Commit 1135966

Browse files
Kimundialexcrichton
authored andcommitted
Made the clone_from implementation for ~T reuse the T itself if
possible by also calling `clone_from` on it. In general, `Clone` implementors that overwrite `clone_from` should try to to use it recursivly for substructures.
1 parent 848f7b7 commit 1135966

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/libstd/clone.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ impl<T: Clone> Clone for ~T {
4545
fn clone(&self) -> ~T { ~(**self).clone() }
4646

4747
/// Perform copy-assignment from `source` by reusing the existing allocation.
48+
#[inline]
4849
fn clone_from(&mut self, source: &~T) {
49-
**self = (**source).clone()
50+
(**self).clone_from(&(**source));
5051
}
5152
}
5253

0 commit comments

Comments
 (0)