Skip to content

Associated types may not all be normalized #20604

Closed
@alexcrichton

Description

@alexcrichton

(or so niko told me)

I believe this code should compile, but it does not compile. Trawling through some logs made Niko think that something wasn't normalized one way or the other, so opening an issue!

#![feature(associated_types)]

trait Hasher {
    type Output;
    fn finish(&self) -> Self::Output;
}

trait Hash<H: Hasher> {
    fn hash(&self, h: &mut H);
}

trait HashState {
    type Hasher: Hasher;
    fn hasher(&self) -> Self::Hasher;
}

struct SipHasher;
impl Hasher for SipHasher {
    type Output = u64;
    fn finish(&self) -> u64 { 4 }
}

impl Hash<SipHasher> for int {
    fn hash(&self, h: &mut SipHasher) {}
}

struct SipState;
impl HashState for SipState {
    type Hasher = SipHasher;
    fn hasher(&self) -> SipHasher { SipHasher }
}

struct Map<S> {
    s: S,
}

impl<S> Map<S>
    where S: HashState,
          <S as HashState>::Hasher: Hasher<Output=u64>,
{
    fn foo<K>(&self) where K: Hash< <S as HashState>::Hasher> {}
}

fn foo<K: Hash<SipHasher>>(map: &Map<SipState>) {
    map.foo();
}

fn main() {}
foo.rs:45:9: 45:14 error: type `&Map<SipState>` does not implement any method in scope named `foo`
foo.rs:45     map.foo();
                  ^~~~~
error: aborting due to previous error

cc @nikomatsakis
cc #17307

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions