Closed
Description
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