Some total ordering relations can only be expressed as partial orders
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
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?)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the issue's proposed changes to Rust's Eq, Ord, PartialEq, and PartialOrd traits, including the wrapper-type examples. Determine whether making Eq and Ord generic would be breaking and whether rustfix could automate compatibility changes. Done means documenting a resolved design direction or turning the proposal into an RFC-ready change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100