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

Hash doesn't work for generic enums #67

Closed
brunocodutra opened this issue Mar 28, 2020 · 1 comment
Closed

Hash doesn't work for generic enums #67

brunocodutra opened this issue Mar 28, 2020 · 1 comment
Labels
bug The crate does not work as expected

Comments

@brunocodutra
Copy link

Describe the bug

The code generated by deriving Hash for generic enumerations leads to issues with type inference.

To Reproduce

#[derive(derivative::Derivative)]
#[derivative(Hash)]
enum Enumeration<T> {
    Variant(T),
}

Expected behavior

I expect valid code akin to the example below to be generated

impl<T: Hash> Hash for Enumeration<T> {
    fn hash<H: Hasher>(&self, state: &mut H) {
        use Enumeration::*;
        match self {
            Variant(t) => t.hash(state),
        }

        discriminant(self).hash(state);
    }
}

Errors

error[E0282]: type annotations needed
 --> src/test.rs:3:6
  |
3 |   enum Enumeration<T> {
  |  ______^
4 | |     Variant(T),
  | |___________^ cannot infer type for type parameter `T` declared on the enum `Enumeration`

Version (please complete the following information):

rustup --version
rustup 1.21.1 (2020-02-23)

cargo --version
cargo 1.43.0-nightly (bda50510d 2020-03-02)

rustc --version
rustc 1.43.0-nightly (c20d7eecb 2020-03-11)
  • Version of derivative: 2.0.2

Additional context

N/A

@brunocodutra brunocodutra added the bug The crate does not work as expected label Mar 28, 2020
@mcarton
Copy link
Owner

mcarton commented Mar 29, 2020

Thanks for the report and the example!

This should now be fixed in v2.1.0.

@mcarton mcarton closed this as completed Mar 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The crate does not work as expected
Projects
None yet
Development

No branches or pull requests

2 participants