Make PartialOrd comparable between different types

Currently, PartialOrd is implemented as follows:

impl<T, A> PartialOrd<Vec<T, A>> for Vec<T, A> where
    T: PartialOrd<T>,
    A: Allocator, 
{ ... }

Currently, PartialEq is implemented as follows:

impl<T, U, A> PartialEq<Vec<U, A>> for Vec<T, A> where
    A: Allocator,
    T: PartialEq<U>, 
{ ... }

It would be great if we could implement PartialOrd like PartialEq is implemented, that is:

impl<T, U, A> PartialOrd<Vec<U, A>> for Vec<T, A> where
    A: Allocator,
    T: PartialOrd<U>,
{ ... }

Is there any reason this wouldn't be a good idea? If it sounds like a good idea, I can try making an RFC for it, although I've never done that before 0_o

I'd suggest trying making the code change and seeing if the compiler still builds. The downside of making these things more general is that it can result in inference breakage -- which is technically allowed, but won't be accepted if the breakage is too large in practice.

What is interference breakage?

I think it's when let foo = bar() was compiling before, because the compiler could infer the type of foo through inference, but not after the change because the type is no longer unambiguous.

Correct. For example, I'd like to allow comparisons with different integer types, but that makes x < 1 not always compile because it gets confused about what type the 1 should be.

Can't we use something like

impl<T, A, U=T> PartialOrd<Vec<U, A>> for Vec<T, A>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.