Skip to content

Commit f653d9f

Browse files
committed
auto merge of #16033 : nham/rust/hash_tuple_impl, r=alexcrichton
Previously the implementation of Hash was limited to tuples of up to arity 8. This increases it to tuples of up to arity 12. Also, the implementation macro for `Hash` used to expand to something like this: impl Hash for (a7,) impl Hash for (a6, a7) impl Hash for (a5, a6, a7) ... This style is inconsistent with the implementations in core::tuple, which look like this: impl Trait for (A,) impl Trait for (A, B) impl Trait for (A, B, C) ... This is perhaps a minor point, but it does mean the documentation pages are inconsistent. Compare the tuple implementations in the documentation for [Hash](http://static.rust-lang.org/doc/master/std/hash/trait.Hash.html) and [PartialOrd](http://static.rust-lang.org/doc/master/core/cmp/trait.PartialOrd.html) This changes the Hash implementation to be consistent with `core::tuple`.
2 parents 9e25010 + e7b41ca commit f653d9f

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/libcollections/hash/mod.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -155,29 +155,36 @@ macro_rules! impl_hash_tuple(
155155
}
156156
);
157157

158-
($A:ident $($B:ident)*) => (
159-
impl<
160-
S: Writer,
161-
$A: Hash<S> $(, $B: Hash<S>)*
162-
> Hash<S> for ($A, $($B),*) {
158+
( $($name:ident)+) => (
159+
impl<S: Writer, $($name: Hash<S>),*> Hash<S> for ($($name,)*) {
160+
#[allow(uppercase_variables)]
163161
#[inline]
164162
fn hash(&self, state: &mut S) {
165163
match *self {
166-
(ref $A, $(ref $B),*) => {
167-
$A.hash(state);
164+
($(ref $name,)*) => {
168165
$(
169-
$B.hash(state);
166+
$name.hash(state);
170167
)*
171168
}
172169
}
173170
}
174171
}
175-
176-
impl_hash_tuple!($($B)*)
177172
);
178173
)
179174

180-
impl_hash_tuple!(a0 a1 a2 a3 a4 a5 a6 a7)
175+
impl_hash_tuple!()
176+
impl_hash_tuple!(A)
177+
impl_hash_tuple!(A B)
178+
impl_hash_tuple!(A B C)
179+
impl_hash_tuple!(A B C D)
180+
impl_hash_tuple!(A B C D E)
181+
impl_hash_tuple!(A B C D E F)
182+
impl_hash_tuple!(A B C D E F G)
183+
impl_hash_tuple!(A B C D E F G H)
184+
impl_hash_tuple!(A B C D E F G H I)
185+
impl_hash_tuple!(A B C D E F G H I J)
186+
impl_hash_tuple!(A B C D E F G H I J K)
187+
impl_hash_tuple!(A B C D E F G H I J K L)
181188

182189
impl<'a, S: Writer, T: Hash<S>> Hash<S> for &'a [T] {
183190
#[inline]

0 commit comments

Comments
 (0)