Skip to content

Redundant impls required when trait bound uses an associated type #20559

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

Closed
jpernst opened this issue Jan 5, 2015 · 3 comments · Fixed by #20757
Closed

Redundant impls required when trait bound uses an associated type #20559

jpernst opened this issue Jan 5, 2015 · 3 comments · Fixed by #20757
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions)

Comments

@jpernst
Copy link

jpernst commented Jan 5, 2015

Now that the stdlib is starting to use associated types, I decided to go back and adapt my code base to use them as well. While doing this, I hit a strange problem where the compiler seems to required multiple impls to satisfy a bound using an associated type. Here's a reduction of my use case:

#![feature(associated_types)]


trait A
{
    type TA;
}

trait B <TB>
{
    fn foo (&self, t : TB) -> TB
    {
        t
    }
}

trait C <TC : A> : B<<TC as A>::TA> { }


struct X;
impl A for X
{
    type TA = i32;
}

struct Y;
impl C<X> for Y { }

// Both of these impls are required for successful compilation
impl B<i32> for Y
{
    fn foo (&self, t : i32) -> i32
    {
        println!("First");
        t
    }
}
impl B<<X as A>::TA> for Y // This impl doesn't appear to actually be used
{
    fn foo (&self, t : i32) -> i32
    {
        println!("Second");
        t
    }
}


fn main ()
{
    let y = Y;
    y.foo(5); // Prints "First"
}

I don't fully understand all the issues surrounding associated types, so this may or may not be a dupe, but it didn't seem obviously similar to any. Here is my rustc version:

rustc 0.13.0-nightly (c6c786671 2015-01-04 00:50:59 +0000)
binary: rustc
commit-hash: c6c786671d692d7b13c2e5c68a53001327b4b125
commit-date: 2015-01-04 00:50:59 +0000
host: x86_64-unknown-linux-gnu
release: 0.13.0-nightly
@jroesch
Copy link
Member

jroesch commented Jan 5, 2015

cc @nikomatsakis

@kmcallister kmcallister added the A-associated-items Area: Associated items (types, constants & functions) label Jan 5, 2015
@nikomatsakis
Copy link
Contributor

Problem is that we're not normalizing the supertraits and so on.

@nikomatsakis
Copy link
Contributor

Got a fix coming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants