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

`derive_partial_eq_without_eq` will trigger for third party crate derives

Open yoav-lavi opened this issue 2 years ago • 2 comments

Summary

error: you are deriving `PartialEq` and can implement `Eq`
  --> my/project/folder/mod.rs:90:48
   |
90 |         #[derive(third_party::Trait, Debug)]
   |                  ^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derive_partial_eq_without_eq
   = note: this error originates in the derive macro `third_party::Trait` (in Nightly builds, run with -Z macro-backtrace for more info)

derive_partial_eq_without_eq seems to trigger for proc macro derives from third party crates which adds PartialEq but not Eq, which while a user can theoretically add an implementation for / derive Eq as well, it could cause breakage when the crate author updates and adds the missing implementation / derive as well

Reproducer

I tried this code:

#[derive(third_party::Trait, Debug)]

I expected to see this happen: No lint error

Instead, this happened: A lint error for derive_partial_eq_without_eq

Version

rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: aarch64-apple-darwin
release: 1.63.0
LLVM version: 14.0.5

Additional Labels

No response

yoav-lavi avatar Aug 11 '22 15:08 yoav-lavi

@rustbot claim

J-ZhengLi avatar Dec 26 '23 02:12 J-ZhengLi

Adding some context fore anyone who would want to try to fix this: in LateContext, the derive attributes don't exist anymore as they were already expanded, making it very tricky to actually check if the type has #[derive(PartialEq)]. A solution would be to actually parse the source code, starting from Span::lo of the type and going back until you finda stop character (like } or ;). This is quite tricky to do though, so not an easy fix.

GuillaumeGomez avatar Jan 15 '24 21:01 GuillaumeGomez