2022-05-21 11:24:00 +00:00
|
|
|
#![allow(unused)]
|
|
|
|
#![warn(clippy::derive_partial_eq_without_eq)]
|
|
|
|
|
|
|
|
// Don't warn on structs that aren't PartialEq
|
2022-06-16 15:39:06 +00:00
|
|
|
pub struct NotPartialEq {
|
2022-05-21 11:24:00 +00:00
|
|
|
foo: u32,
|
|
|
|
bar: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Eq can be derived but is missing
|
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2022-06-16 15:39:06 +00:00
|
|
|
pub struct MissingEq {
|
2022-05-21 11:24:00 +00:00
|
|
|
foo: u32,
|
|
|
|
bar: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Eq is derived
|
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-16 15:39:06 +00:00
|
|
|
pub struct NotMissingEq {
|
2022-05-21 11:24:00 +00:00
|
|
|
foo: u32,
|
|
|
|
bar: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Eq is manually implemented
|
|
|
|
#[derive(PartialEq)]
|
2022-06-16 15:39:06 +00:00
|
|
|
pub struct ManualEqImpl {
|
2022-05-21 11:24:00 +00:00
|
|
|
foo: u32,
|
|
|
|
bar: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Eq for ManualEqImpl {}
|
|
|
|
|
|
|
|
// Cannot be Eq because f32 isn't Eq
|
|
|
|
#[derive(PartialEq)]
|
2022-06-16 15:39:06 +00:00
|
|
|
pub struct CannotBeEq {
|
2022-05-21 11:24:00 +00:00
|
|
|
foo: u32,
|
|
|
|
bar: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't warn if PartialEq is manually implemented
|
2022-06-16 15:39:06 +00:00
|
|
|
pub struct ManualPartialEqImpl {
|
2022-05-21 11:24:00 +00:00
|
|
|
foo: u32,
|
|
|
|
bar: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq for ManualPartialEqImpl {
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
self.foo == other.foo && self.bar == other.bar
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generic fields should be properly checked for Eq-ness
|
2022-06-16 15:39:06 +00:00
|
|
|
#[derive(PartialEq, Eq)]
|
|
|
|
pub struct GenericNotEq<T: Eq, U: PartialEq> {
|
2022-05-21 11:24:00 +00:00
|
|
|
foo: T,
|
|
|
|
bar: U,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-16 15:39:06 +00:00
|
|
|
pub struct GenericEq<T: Eq, U: Eq> {
|
2022-05-21 11:24:00 +00:00
|
|
|
foo: T,
|
|
|
|
bar: U,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-16 15:39:06 +00:00
|
|
|
pub struct TupleStruct(u32);
|
2022-05-21 11:24:00 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-16 15:39:06 +00:00
|
|
|
pub struct GenericTupleStruct<T: Eq>(T);
|
2022-05-21 11:24:00 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
2022-06-16 15:39:06 +00:00
|
|
|
pub struct TupleStructNotEq(f32);
|
2022-05-21 11:24:00 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-16 15:39:06 +00:00
|
|
|
pub enum Enum {
|
2022-05-21 11:24:00 +00:00
|
|
|
Foo(u32),
|
|
|
|
Bar { a: String, b: () },
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-16 15:39:06 +00:00
|
|
|
pub enum GenericEnum<T: Eq, U: Eq, V: Eq> {
|
2022-05-21 11:24:00 +00:00
|
|
|
Foo(T),
|
|
|
|
Bar { a: U, b: V },
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
2022-06-16 15:39:06 +00:00
|
|
|
pub enum EnumNotEq {
|
2022-05-21 11:24:00 +00:00
|
|
|
Foo(u32),
|
|
|
|
Bar { a: String, b: f32 },
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that rustfix works properly when `PartialEq` has other derives on either side
|
|
|
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
2022-06-16 15:39:06 +00:00
|
|
|
pub struct RustFixWithOtherDerives;
|
2022-05-21 11:24:00 +00:00
|
|
|
|
2022-06-16 15:39:06 +00:00
|
|
|
#[derive(PartialEq, Eq)]
|
|
|
|
pub struct Generic<T>(T);
|
2022-06-04 11:34:07 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-16 15:39:06 +00:00
|
|
|
pub struct GenericPhantom<T>(core::marker::PhantomData<T>);
|
|
|
|
|
|
|
|
mod _hidden {
|
|
|
|
#[derive(PartialEq, Eq)]
|
|
|
|
pub struct Reexported;
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
|
|
|
pub struct InPubFn;
|
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
pub(crate) struct PubCrate;
|
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
pub(super) struct PubSuper;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub use _hidden::Reexported;
|
|
|
|
pub fn _from_mod() -> _hidden::InPubFn {
|
|
|
|
_hidden::InPubFn
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
struct InternalTy;
|
2022-06-04 11:34:07 +00:00
|
|
|
|
2024-01-25 18:17:36 +00:00
|
|
|
// This is a `non_exhaustive` type so should not warn.
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
#[non_exhaustive]
|
|
|
|
pub struct MissingEqNonExhaustive {
|
|
|
|
foo: u32,
|
|
|
|
bar: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a `non_exhaustive` type so should not warn.
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub struct MissingEqNonExhaustive1 {
|
|
|
|
foo: u32,
|
|
|
|
#[non_exhaustive]
|
|
|
|
bar: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a `non_exhaustive` type so should not warn.
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
#[non_exhaustive]
|
|
|
|
pub enum MissingEqNonExhaustive2 {
|
|
|
|
Foo,
|
|
|
|
Bar,
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a `non_exhaustive` type so should not warn.
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum MissingEqNonExhaustive3 {
|
|
|
|
Foo,
|
|
|
|
#[non_exhaustive]
|
|
|
|
Bar,
|
|
|
|
}
|
|
|
|
|
2022-05-21 11:24:00 +00:00
|
|
|
fn main() {}
|