Implement Clone for tuples #5692

Closed
wants to merge 1 commit into
from

3 participants

@Aatch

This implements the clone interface for tuples and adds a test to match. The implementation is only on tuples that have elements that are themselves clone-able. This should allow for `#[deriving(Clone)] on nominal types that contain tuples somewhere.

@thestinger thestinger commented on the diff Apr 3, 2013
src/libcore/tuple.rs
@@ -46,6 +47,15 @@ impl<T:Copy,U:Copy> CopyableTuple<T, U> for (T, U) {
}
+impl<T:Clone,U:Clone> Clone for (T, U) {
+ fn clone(&self) -> (T, U) {
+ let (a, b) = match *self {
@thestinger
thestinger added a line comment Apr 3, 2013

could you use let (ref a, ref b) = *self here? or does that hit something like an ICE?

@huonw
The Rust Programming Language member
huonw added a line comment Apr 3, 2013

Yep. #3874 and #3235 (mainly the latter).

@bstrie
bstrie added a line comment Apr 3, 2013

Also, presumably, #5689, which for all I know might be a subset of one of those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@thestinger

saw approval from thestinger
at Aatch@e2bffb7

merging Aatch/rust/tuple-clone = e2bffb7 into auto

Aatch/rust/tuple-clone = e2bffb7 merged ok, testing candidate = d4e9a415

saw approval from thestinger
at Aatch@e2bffb7

merging Aatch/rust/tuple-clone = e2bffb7 into auto

Aatch/rust/tuple-clone = e2bffb7 merged ok, testing candidate = afd5cba

fast-forwarding incoming to auto = afd5cba

@bors bors added a commit that referenced this pull request Apr 3, 2013
@bors bors auto merge of #5692 : Aatch/rust/tuple-clone, r=thestinger
This implements the clone interface for tuples and adds a test to match. The implementation is only on tuples that have elements that are themselves clone-able. This should allow for `#[deriving(Clone)] on nominal types that contain tuples somewhere.
afd5cba
@bors bors closed this Apr 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment