diff options
| author | bors <bors@rust-lang.org> | 2014-07-29 04:26:42 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-07-29 04:26:42 +0000 |
| commit | f653d9f9bf9b69211226dabd13db188afd6b1fdb (patch) | |
| tree | 54ba292ec5b734b90a59fd5823a9df29eae7836f | |
| parent | 9e250109f9d40deefbca1a42f602d3f0b59ca1e6 (diff) | |
| parent | e7b41caba8b968450717b487087b5a2cdc10461a (diff) | |
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`.
| -rw-r--r-- | src/libcollections/hash/mod.rs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/libcollections/hash/mod.rs b/src/libcollections/hash/mod.rs index 35738320715..6f8b63953e2 100644 --- a/src/libcollections/hash/mod.rs +++ b/src/libcollections/hash/mod.rs @@ -155,29 +155,36 @@ macro_rules! impl_hash_tuple( } ); - ($A:ident $($B:ident)*) => ( - impl< - S: Writer, - $A: Hash<S> $(, $B: Hash<S>)* - > Hash<S> for ($A, $($B),*) { + ( $($name:ident)+) => ( + impl<S: Writer, $($name: Hash<S>),*> Hash<S> for ($($name,)*) { + #[allow(uppercase_variables)] #[inline] fn hash(&self, state: &mut S) { match *self { - (ref $A, $(ref $B),*) => { - $A.hash(state); + ($(ref $name,)*) => { $( - $B.hash(state); + $name.hash(state); )* } } } } - - impl_hash_tuple!($($B)*) ); ) -impl_hash_tuple!(a0 a1 a2 a3 a4 a5 a6 a7) +impl_hash_tuple!() +impl_hash_tuple!(A) +impl_hash_tuple!(A B) +impl_hash_tuple!(A B C) +impl_hash_tuple!(A B C D) +impl_hash_tuple!(A B C D E) +impl_hash_tuple!(A B C D E F) +impl_hash_tuple!(A B C D E F G) +impl_hash_tuple!(A B C D E F G H) +impl_hash_tuple!(A B C D E F G H I) +impl_hash_tuple!(A B C D E F G H I J) +impl_hash_tuple!(A B C D E F G H I J K) +impl_hash_tuple!(A B C D E F G H I J K L) impl<'a, S: Writer, T: Hash<S>> Hash<S> for &'a [T] { #[inline] |
