Skip to content

Interesting error message with custom hashers #12631

Closed
@alexcrichton

Description

@alexcrichton
#[feature(default_type_params)];

extern crate collections;

use std::hash::{Hash, Hasher};

type IntSet = collections::HashSet<int, IntHasher>;

struct IntHasher;

impl Hasher<int> for IntHasher {
    fn hash<T: Hash<int>>(&self, t: &T) -> u64 {
        let mut state = 0;
        t.hash(&mut state);
        state as u64
    }
}

fn main() {
    let mut s: IntSet = collections::HashSet::with_hasher(IntHasher);
    s.insert(3);
    println!("{}", s.contains(&3));
}
$ rustc foo.rs
foo.rs:21:5: 21:16 error: failed to find an implementation of trait std::io::Writer for int
foo.rs:21     s.insert(3);
              ^~~~~~~~~~~

I'm not sure why it's saying that there's no implementation of Writer for int. While true, it shouldn't be looking for that. I think this has to do with default type parameters on Hash.

Note that I forgot to provide impl Hash<int> for int, so it's legitimate that I receive an error, I don't believe I should receive the above error, however. I've also found out that it's illegal anyway to say impl Hash<int> for int, but seems like the message should change?

cc @eddyb

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