Skip to content

deriving(Hash) on enum generates method call on generic integer (1.hash()) #18573

Closed
@klutzy

Description

@klutzy
#[deriving(Hash)]
enum E {
    A = 1,
    B,
}
error: unable to infer enough type information to locate the impl of the trait `collections::hash::Hash` for the type `_`; type annotations required
#[deriving(Hash)]
           ^~~~

rustc --pretty=expanded output:

#![crate_type = "lib"]
#![feature(phase)]
#![no_std]
#![feature(globs)]
#[phase(plugin, link)]
extern crate "std" as std;
#[prelude_import]
use std::prelude::*;

enum E { A = 1, B, }
#[automatically_derived]
impl ::std::hash::Hash for E {
    #[inline]
    fn hash(&self, __arg_0: &mut ::std::hash::sip::SipState) {
        match (&*self,) {
            (&A,) => { 1.hash(__arg_0); }
            (&B,) => { 1u.hash(__arg_0); }
        }
    }
}

For A = 1, rustc generates 1.hash(__arg_0) but it doesn't compile because 1 is generic integer.

Moreoever, for B rustc generates 1u.hash(__arg_0) but it should be 2u.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions