Skip to content

Commit e0b0853

Browse files
author
blake2-ppc
committed
std: Implement traits for the one-tuple
(A,) did not have the trait implementations of 2- to 12- tuples.
1 parent a2e3cdf commit e0b0853

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

src/libstd/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub use from_str::FromStr;
6969
pub use to_bytes::IterBytes;
7070
pub use to_str::{ToStr, ToStrConsume};
7171
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
72+
pub use tuple::{CloneableTuple1, ImmutableTuple1};
7273
pub use tuple::{CloneableTuple2, CloneableTuple3, CloneableTuple4, CloneableTuple5};
7374
pub use tuple::{CloneableTuple6, CloneableTuple7, CloneableTuple8, CloneableTuple9};
7475
pub use tuple::{CloneableTuple10, CloneableTuple11, CloneableTuple12};

src/libstd/tuple.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ macro_rules! tuple_impls {
148148
$(fn $get_fn(&self) -> $T;)+
149149
}
150150

151-
impl<$($T:Clone),+> $cloneable_trait<$($T),+> for ($($T),+) {
151+
impl<$($T:Clone),+> $cloneable_trait<$($T),+> for ($($T,)+) {
152152
$(
153153
#[inline]
154154
fn $get_fn(&self) -> $T {
@@ -161,7 +161,7 @@ macro_rules! tuple_impls {
161161
$(fn $get_ref_fn<'a>(&'a self) -> &'a $T;)+
162162
}
163163

164-
impl<$($T),+> $immutable_trait<$($T),+> for ($($T),+) {
164+
impl<$($T),+> $immutable_trait<$($T),+> for ($($T,)+) {
165165
$(
166166
#[inline]
167167
fn $get_ref_fn<'a>(&'a self) -> &'a $T {
@@ -170,59 +170,59 @@ macro_rules! tuple_impls {
170170
)+
171171
}
172172

173-
impl<$($T:Clone),+> Clone for ($($T),+) {
174-
fn clone(&self) -> ($($T),+) {
175-
($(self.$get_ref_fn().clone()),+)
173+
impl<$($T:Clone),+> Clone for ($($T,)+) {
174+
fn clone(&self) -> ($($T,)+) {
175+
($(self.$get_ref_fn().clone(),)+)
176176
}
177177
}
178178

179179
#[cfg(not(test))]
180-
impl<$($T:Eq),+> Eq for ($($T),+) {
180+
impl<$($T:Eq),+> Eq for ($($T,)+) {
181181
#[inline]
182-
fn eq(&self, other: &($($T),+)) -> bool {
182+
fn eq(&self, other: &($($T,)+)) -> bool {
183183
$(*self.$get_ref_fn() == *other.$get_ref_fn())&&+
184184
}
185185
#[inline]
186-
fn ne(&self, other: &($($T),+)) -> bool {
186+
fn ne(&self, other: &($($T,)+)) -> bool {
187187
!(*self == *other)
188188
}
189189
}
190190

191191
#[cfg(not(test))]
192-
impl<$($T:TotalEq),+> TotalEq for ($($T),+) {
192+
impl<$($T:TotalEq),+> TotalEq for ($($T,)+) {
193193
#[inline]
194-
fn equals(&self, other: &($($T),+)) -> bool {
194+
fn equals(&self, other: &($($T,)+)) -> bool {
195195
$(self.$get_ref_fn().equals(other.$get_ref_fn()))&&+
196196
}
197197
}
198198

199199
#[cfg(not(test))]
200-
impl<$($T:Ord),+> Ord for ($($T),+) {
200+
impl<$($T:Ord),+> Ord for ($($T,)+) {
201201
#[inline]
202-
fn lt(&self, other: &($($T),+)) -> bool {
202+
fn lt(&self, other: &($($T,)+)) -> bool {
203203
lexical_lt!($(self.$get_ref_fn(), other.$get_ref_fn()),+)
204204
}
205205
#[inline]
206-
fn le(&self, other: &($($T),+)) -> bool { !(*other).lt(&(*self)) }
206+
fn le(&self, other: &($($T,)+)) -> bool { !(*other).lt(&(*self)) }
207207
#[inline]
208-
fn ge(&self, other: &($($T),+)) -> bool { !(*self).lt(other) }
208+
fn ge(&self, other: &($($T,)+)) -> bool { !(*self).lt(other) }
209209
#[inline]
210-
fn gt(&self, other: &($($T),+)) -> bool { (*other).lt(&(*self)) }
210+
fn gt(&self, other: &($($T,)+)) -> bool { (*other).lt(&(*self)) }
211211
}
212212

213213
#[cfg(not(test))]
214-
impl<$($T:TotalOrd),+> TotalOrd for ($($T),+) {
214+
impl<$($T:TotalOrd),+> TotalOrd for ($($T,)+) {
215215
#[inline]
216-
fn cmp(&self, other: &($($T),+)) -> Ordering {
216+
fn cmp(&self, other: &($($T,)+)) -> Ordering {
217217
lexical_cmp!($(self.$get_ref_fn(), other.$get_ref_fn()),+)
218218
}
219219
}
220220

221221
#[cfg(not(test))]
222-
impl<$($T:Zero),+> Zero for ($($T),+) {
222+
impl<$($T:Zero),+> Zero for ($($T,)+) {
223223
#[inline]
224-
fn zero() -> ($($T),+) {
225-
($(Zero::zero::<$T>()),+)
224+
fn zero() -> ($($T,)+) {
225+
($(Zero::zero::<$T>(),)+)
226226
}
227227
#[inline]
228228
fn is_zero(&self) -> bool {
@@ -259,6 +259,10 @@ macro_rules! lexical_cmp {
259259

260260

261261
tuple_impls! {
262+
(CloneableTuple1, ImmutableTuple1) {
263+
(n0, n0_ref) -> A { (ref a,) => a }
264+
}
265+
262266
(CloneableTuple2, ImmutableTuple2) {
263267
(n0, n0_ref) -> A { (ref a,_) => a }
264268
(n1, n1_ref) -> B { (_,ref b) => b }

0 commit comments

Comments
 (0)