Open
Description
The following example currently fails to compile:
pub trait Foo {
type TypeA;
type TypeB: Bar<Self::TypeA>;
}
pub trait Bar<T> {
}
pub struct ImplsBar;
impl<T> Bar<T> for ImplsBar {
}
impl<T> Foo for T {
type TypeA = u8;
default type TypeB = ImplsBar;
}
with message:
<anon>:15:9: 15:12 error: the trait `Bar<u8>` is not implemented for the type `<T as Foo>::TypeB` [E0277]
<anon>:15 impl<T> Foo for T {
The problem seems to be that the type checker is using a projection of TypeB
to actually check the impl's definition of TypeB
against its bounds. But because it's marked default
, the item cannot be projected.
In general, we should loosen up the rules on projections when checking an impl -- but doing so soundly is tricky. It clearly doesn't work to just allow all projections to go through (a la "trans mode"), because in general items could be replaced in more specialized impls. But it does seem reasonable to allow projecting the current item being impled (for any trait ref covered by the impl), because any specialization of that item will be rechecked under its own constraints.