Skip to content

Implement Hash for tuples of up to arity 12. Also change the style to be consistent with core::tuple #16033

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

Merged
merged 1 commit into from
Jul 29, 2014

Conversation

nham
Copy link
Contributor

@nham nham commented Jul 27, 2014

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 and PartialOrd

This changes the Hash implementation to be consistent with core::tuple.

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)
Copy link
Member

Choose a reason for hiding this comment

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

Why move from the one line invocation to 12 lines of invocations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe this is really silly, but with one line invocation and a recursive macro it ends up coming out like:

impl Trait for (A, B, C, D)
impl Trait for (B, C, D)
impl Trait for (C, D)
impl Trait for (D,)

I want it to come out

impl Trait for (A,)
impl Trait for (A, B)
impl Trait for (A, B, C)
impl Trait for (A, B, C, D)

Copy link
Member

Choose a reason for hiding this comment

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

In that case, could the recursive macro invocation be placed first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That will help a bit, but it will still expand to

impl Trait for (D,)
impl Trait for (C, D)
impl Trait for (B, C, D)
impl Trait for (A, B, C, D)

I was mostly doing it so that the implementation for a 1-tuple would use "A", for a 2-tuple would use "A, B", for a 3-tuple would use "A, B, C", etc. Maybe this is too minor to worry about.

Copy link
Member

Choose a reason for hiding this comment

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

Oh well :(

bors added a commit that referenced this pull request Jul 29, 2014
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`.
@bors bors closed this Jul 29, 2014
@bors bors merged commit e7b41ca into rust-lang:master Jul 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants