rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

`derive_partial_eq_without_eq` false positive in struct using traits

Open conradoplg opened this issue 2 years ago • 2 comments

Summary

This is a somewhat convoluted scenario for which I can't provide a concise textual explanation and I couldn't make the reproducer any simpler. But it wrongly emits derive_partial_eq_without_eq when it clearly already has Eq.

Lint Name

derive_partial_eq_without_eq

Reproducer

I tried this code:

pub trait Group {
    type Element: Eq + PartialEq;
}

pub trait Ciphersuite {
    type Group: Group;
}

#[derive(PartialEq, Eq)]
pub struct Public<C: Ciphersuite>(<C::Group as Group>::Element);

fn main() {}

I saw this happen:

warning: you are deriving `PartialEq` and can implement `Eq`
 --> src/main.rs:9:10
  |
9 | #[derive(PartialEq, Eq)]
  |          ^^^^^^^^^ 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

warning: `partialeq` (bin "partialeq") generated 1 warning

I expected to see this happen:

No warnings emitted.

Version

rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: x86_64-unknown-linux-gnu
release: 1.63.0
LLVM version: 14.0.5

Additional Labels

No response

conradoplg avatar Sep 01 '22 21:09 conradoplg

This is the faulty line: https://github.com/rust-lang/rust-clippy/blob/e120fb10c60a27670c72e7ec99e93d16c045f493/clippy_lints/src/derive.rs#L472, so either https://github.com/rust-lang/rust-clippy/blob/e120fb10c60a27670c72e7ec99e93d16c045f493/clippy_lints/src/derive.rs#L493 gives wrong envs or some type parameters needs to be given in that case. Maybe @Jarcho you have an idea of what could be wrong? You wrote the latter method

kraktus avatar Sep 17 '22 14:09 kraktus

huh, the problem still exist so... don't mind if I try~

@rustbot claim

J-ZhengLi avatar Feb 27 '24 10:02 J-ZhengLi