Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Clone for tuples #5692

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/libcore/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

//! Operations on tuples

use clone::Clone;
use kinds::Copy;
use vec;

Expand Down Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

(ref a, ref b) => (a, b)
};
(a.clone(), b.clone())
}
}

pub trait ImmutableTuple<T, U> {
fn first_ref(&self) -> &'self T;
fn second_ref(&self) -> &'self U;
Expand Down Expand Up @@ -252,3 +262,10 @@ fn test_tuple() {
assert!(('a', 2).swap() == (2, 'a'));
}

#[test]
fn test_clone() {
let a = (1, ~"2");
let b = a.clone();
assert!(a.first() == b.first());
assert!(a.second() == b.second());
}