rust-lang / rust-lang/rust-clippy

incomplete ordering trait impls lint

Open
#2,994 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint L-correctness
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

When a user derives or implement PartialOrd<T> for T we can call it a day.

However, when a user implements PartialOrd<U> for T, then for transitivity ("a < b and b < c implies a < c") to hold the user needs to provide more trait implementations (proof below):

  • PartialOrd<T> for T
  • PartialOrd<U> for U
  • PartialOrd<T> for U

All these implementations need to "cooperate" and implement the same semantics for everything to work and I don't think we can check that, not statically at least. But we could at least check that they are provided.


Proof:

Consider: a: T, b: U, c: T

  • a < b is ok, since PartialOrd<U> for T is implemented,
  • b < c does not type check unless the user also implements PartialOrd<T> for U,
  • a < c does not type check unless the user also implements PartialOrd<T> for T,

Consider the opposite case: a: U, b: T, c: U where a < c requires PartialOrd<U> for U.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing Rust Clippy lint implementations and their tests, then trace how trait implementations are inspected. The intended result is a lint that detects a cross-type PartialOrd for T without the three related PartialOrd implementations described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.