rust-lang / rust-lang/rust-clippy

derive_partial_eq_without_eq should acknowledge the constraint it adds

Open
#9,063 6 comments 22 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive L-nursery
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

The derive_partial_eq_without_eq lint and its documentation recommends deriving Eq whenever PartialEq is implemented on a public type. However, doing so may constrain the evolution of a library: adding derive(Eq) prevents later adding a private field, or public field or variant in a non_exhaustive enum or struct, which contains an !Eq type such as f64.

Notably, Clippy reported this lint on my library's non-exhaustive error enums — types that are more likely than most to gain new variants with new kinds of data.

At a minimum, the lint documentation should acknowledge that adding Eq constrains future choices.

Lint Name

derive_partial_eq_without_eq

Reproducer

I tried this code:

#[derive(Clone, Debug, PartialEq)]
pub struct Value {
    x: bool,
    // y: f64,            // adding this line would not be a breaking change, but it conflicts with `derive(Eq)`
}

I saw this happen:

warning: you are deriving `PartialEq` and can implement `Eq`
 --> src/lib.rs:1:24
  |
1 | #[derive(Clone, Debug, PartialEq)]
  |                        ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq`
  |
  = note: `#[warn(clippy::derive_partial_eq_without_eq)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derive_partial_eq_without_eq
Version
Tested with clippy 0.1.63 (2022-06-27 2f3ddd9) on Rust Playground

(The original detection was with `rustc 1.64.0-nightly (c80c4b8fd 2022-06-26)` — sorry, neither my CI nor the Playground provides `rustc -Vv` output)
Additional Labels

No response

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 documentation for the derive_partial_eq_without_eq lint and review its recommendation against the provided Value reproducer. Update the explanation so it acknowledges that deriving Eq can constrain future API evolution, then verify the rendered lint documentation and relevant documentation checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation, tooling
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.