# Make PartialOrd comparable between different types

**URL:** <https://internals.rust-lang.org/t/make-partialord-comparable-between-different-types/15733>\
**Category:** language design\
**Created:** [December 6, 2021, 7:07pm UTC](https://internals.rust-lang.org/t/make-partialord-comparable-between-different-types/15733 "2021-12-06T19:07:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheButlah](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@TheButlah](https://internals.rust-lang.org/u/TheButlah)\
**Post date:** [December 6, 2021, 7:07pm UTC](https://internals.rust-lang.org/t/make-partialord-comparable-between-different-types/15733/1 "2021-12-06T19:07:04Z")

</div>

Currently, PartialOrd is implemented as follows:

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

```

Currently, PartialEq is implemented as follows:

```rust
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:

```rust
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

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [December 6, 2021, 7:13pm UTC](https://internals.rust-lang.org/t/make-partialord-comparable-between-different-types/15733/2 "2021-12-06T19:13:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TheButlah](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@TheButlah](https://internals.rust-lang.org/u/TheButlah)\
**Post date:** [December 6, 2021, 7:41pm UTC](https://internals.rust-lang.org/t/make-partialord-comparable-between-different-types/15733/3 "2021-12-06T19:41:55Z")

</div>

What is interference breakage?

---

<div class="post-metadata">

**Author:** ![robinm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/robinm/32/6255_2.png) [@robinm](https://internals.rust-lang.org/u/robinm)\
**Post date:** [December 6, 2021, 7:53pm UTC](https://internals.rust-lang.org/t/make-partialord-comparable-between-different-types/15733/4 "2021-12-06T19:53:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [December 6, 2021, 8:25pm UTC](https://internals.rust-lang.org/t/make-partialord-comparable-between-different-types/15733/5 "2021-12-06T20:25:54Z")

</div>

> [@robinm](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![robinm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/robinm/32/6255_2.png) [@robinm](https://internals.rust-lang.org/u/robinm)\
**Post date:** [December 6, 2021, 9:23pm UTC](https://internals.rust-lang.org/t/make-partialord-comparable-between-different-types/15733/6 "2021-12-06T21:23:07Z")

</div>

Can't we use something like

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

```

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 6, 2022, 9:23pm UTC](https://internals.rust-lang.org/t/make-partialord-comparable-between-different-types/15733/7 "2022-03-06T21:23:27Z")

</div>

Closed on March 6, 2022, 9:23pm UTC

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