-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive for derive_partial_eq_without_eq
when using PhantomData
#8867
Comments
I was about to post an almost identical issue, so instead I'll just affirm this happens, and that I found a slightly smaller repro (dependencies wise, not bytes wise): #[derive(Eq, PartialEq)]
pub struct Outer<T>(Inner<T>);
struct Inner<T>(T);
impl<T> PartialEq for Inner<T> {
fn eq(&self, other: &Self) -> bool {
loop {}
}
}
impl<T> Eq for Inner<T> {} (note that the loop there causes a different warning- about empty loops and CPU cycles, completely true in this context- which could be removed by using Note that the very similar: #[derive(Eq, PartialEq)]
pub struct Outer<T>(Inner<T>);
struct Inner<T>(T);
impl<T> PartialEq for Inner<T> where T: PartialEq {
fn eq(&self, other: &Self) -> bool {
loop {}
}
}
impl<T> Eq for Inner<T> where T: Eq {} does not trigger this, so the issue seems to be with the more general bounds on (immediately edited to mark the last snippet as rust) |
Note that this is a very very fresh regression:
Which means that the first "bad" nightly is:
|
Can confirm this, just hit the issue in a CI run. I was first thinking Clippy had a bug with ordering
However, changing to |
457: Fix clippy false positive r=jonasbb a=jonasbb rust-lang/rust-clippy#8867 bors merge Co-authored-by: Jonas Bushart <jonas@bushart.org>
457: Fix clippy false positive r=jonasbb a=jonasbb rust-lang/rust-clippy#8867 bors merge Co-authored-by: Jonas Bushart <jonas@bushart.org>
This bug got me recently, and I wanted to point out a small change can be made to @izik1 2nd example and make it trip up the bug.
Adding the second bound, and having it on the type parameter in the struct, will cause the clippy error.
|
Also impacted by this when trying to conform to the new lint. |
Same here, I suggest that this lint should be removed from |
rust-lang/rust-clippy#8867 is fixed, and a false positive is no longer reported.
rust-lang/rust-clippy#8867 is fixed, and a false positive is no longer reported.
Summary
A struct with
PhantomData
will trigger thederive_partial_eq_without_eq
even though it derives bothEq, PartialEq
.clippy 0.1.63 (9257f5a 2022-05-21)
Lint Name
derive_partial_eq_without_eq
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
No warning.
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: