-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
T-libs-apiRelevant to the library API team, which will review and decide on the RFC.Relevant to the library API team, which will review and decide on the RFC.
Description
TL;DR: one cannot impl Ord<Foo> for Bar
.
Currently, we can stablish strict and non-strict partial ordering relations between types:
impl PartialEq<Foo> for Bar { ... }
impl PartialOrd<Foo> for Bar { ... }
but there is no way to state that such a relation is a total order because Ord
and Eq
are not generic over the RHS
like PartialOrd
and PartialEq
are.
Is this an oversight?
I would find this useful when implementing ordering relations for wrapper types for which it makes no sense to implement Deref
. For example:
impl PartialOrd<Wrapping<i32>> for i32 { ... } // TODAY OK
impl PartialEq<Wrapping<i32>> for i32 { ... } // TODAY OK
impl Eq<Wrapping<i32>> for i32 { ... } // TODAY ERROR
impl Ord<Wrapping<i32>> for i32 { ... } // TODAY ERROR
To solve this we would probably need to change Eq
and Ord
from:
pub trait Eq: PartialEq<Self> { ... }
pub trait Ord: Eq + PartialOrd<Self> { ... }
to
pub trait Eq<RHS=Self>: PartialEq<RHS> { ... }
pub trait Ord<RHS=Self>: Eq<RHS> + PartialOrd<RHS> { ... }
Would this be a breaking change? (if so, could it be fixed automatically by rustfix?)
scottmcm, strega-nil, Rapptz and taylordotfish
Metadata
Metadata
Assignees
Labels
T-libs-apiRelevant to the library API team, which will review and decide on the RFC.Relevant to the library API team, which will review and decide on the RFC.