E0275 with orphan rule workaround attempt

Can someone explain why this error occurs?:

Note that if impl<'a, T> Display for Foster<'a, Vec<T>> is made inactive, along with the usage a the end, leaving the slice impl and usage, it compiles and runs.

I believe it's trying to unify a type inference variable against your multiple implementations (to check for overlap) and getting into a recursion loop when it does so. Definitely it's not the kindest error.

The first and third implementations do overlap from a coherence POV as Vec<T> could conceivably implement Display for some T: Display someday in a way that's supposed to be SemVer compatible.

So could [T], but...

...this part is because the compiler can easily prove that these two implementations don't overlap:

impl<'a, T: Display> Display for Foster<'a, T> { .. }
impl<'a, T> Display for Foster<'a, [T]>
where
    Foster<'a, T>: Display,

Because the first one has an implicit T: Sized bound. If you change it to this:

//                  vvvvvvvv
impl<'a, T: Display + ?Sized> Display for Foster<'a, T> { .. }

Then the first two implementations cause an overflow as well.

1 Like

Ouch.

I guess I need negative traits to make this work.

Thanks.