Why do these impls conflict unless I name the associated type?

Consider the following minimized example (playground link):

pub struct Struct<T, A: WithAssoc<T = T>> {
    field: A,
}

pub trait WithAssoc {
    type T;
}

pub trait Trait<T> {}
pub trait Trait2<T> {}

impl<A: WithAssoc> Trait<A::T> for Struct<A::T, A> {}

//conflicting implementation?
// impl<A: WithAssoc> Trait<&A::T> for Struct<A::T, A> {}

impl<T, A: WithAssoc<T = T>> Trait2<T> for Struct<T, A> {}

impl<T, A: WithAssoc<T = T>> Trait2<&T> for Struct<T, A> {}

The first version produces an error about conflicting implementations while the second version compiles fine. As far as I understand the two ways of writing these two impl's should be equivalent. Is this a bug or shortcoming in the trait solver or am I misunderstanding something?

1 Like

They are equivalent in terms of what types implement which trait+parameters, so some sort of shortcoming. I could hypothesize on why exactly, but I'd be guessing.

1 Like