From 42ce54653a383427f86ced45d6d51941a0942539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20L=C3=B6bel?= Date: Tue, 18 Mar 2014 23:16:21 +0100 Subject: [PATCH] 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. --- src/libstd/clone.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libstd/clone.rs b/src/libstd/clone.rs index ce5f056622f36..cf5a9c6711c62 100644 --- a/src/libstd/clone.rs +++ b/src/libstd/clone.rs @@ -45,8 +45,9 @@ impl Clone for ~T { fn clone(&self) -> ~T { ~(**self).clone() } /// Perform copy-assignment from `source` by reusing the existing allocation. + #[inline] fn clone_from(&mut self, source: &~T) { - **self = (**source).clone() + (**self).clone_from(&(**source)); } }