Type inference picks the wrong supertrait

This code:

trait Foo: PartialOrd + PartialOrd<<Self as Foo>::A> {
    type A;

trait Bar {
    type B: Foo;

    fn bar(&self) -> Self::B;

fn baz<T: Bar>(x: T, y: T) -> bool { <

fails to compile with this error:

error[E0308]: mismatched types
  --> src/
12 | <
   |               ^^^^^^^ expected Foo::A, found Bar::B
   = note: expected associated type `<<T as Bar>::B as Foo>::A`
              found associated type `<T as Bar>::B`

which seems to imply that type inference is trying to call the B: PartialOrd<B::A> impl instead of the B: PartialOrd<B> impl which is also available.

Is this a bug or just an (intentional/unintentional) limitation of Rust's type inference?

Is there a better workaround than this:

<T::B as PartialOrd>::partial_cmp(&, & == Some(Ordering::Less)


  • This was a bug/limitation of Rust that was fixed by The first Rust release with the fix was 1.49.0.