2023-04-20 14:37:15 +00:00
|
|
|
//@run-rustfix
|
2022-05-06 07:10:11 +00:00
|
|
|
|
|
|
|
#![allow(unused)]
|
|
|
|
#![warn(clippy::derive_partial_eq_without_eq)]
|
|
|
|
|
|
|
|
// Don't warn on structs that aren't PartialEq
|
2022-06-04 21:28:23 +00:00
|
|
|
pub struct NotPartialEq {
|
2022-05-06 07:10:11 +00:00
|
|
|
foo: u32,
|
|
|
|
bar: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Eq can be derived but is missing
|
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2022-06-04 21:28:23 +00:00
|
|
|
pub struct MissingEq {
|
2022-05-06 07:10:11 +00:00
|
|
|
foo: u32,
|
|
|
|
bar: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Eq is derived
|
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-04 21:28:23 +00:00
|
|
|
pub struct NotMissingEq {
|
2022-05-06 07:10:11 +00:00
|
|
|
foo: u32,
|
|
|
|
bar: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Eq is manually implemented
|
|
|
|
#[derive(PartialEq)]
|
2022-06-04 21:28:23 +00:00
|
|
|
pub struct ManualEqImpl {
|
2022-05-06 07:10:11 +00:00
|
|
|
foo: u32,
|
|
|
|
bar: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Eq for ManualEqImpl {}
|
|
|
|
|
|
|
|
// Cannot be Eq because f32 isn't Eq
|
|
|
|
#[derive(PartialEq)]
|
2022-06-04 21:28:23 +00:00
|
|
|
pub struct CannotBeEq {
|
2022-05-06 07:10:11 +00:00
|
|
|
foo: u32,
|
|
|
|
bar: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't warn if PartialEq is manually implemented
|
2022-06-04 21:28:23 +00:00
|
|
|
pub struct ManualPartialEqImpl {
|
2022-05-06 07:10:11 +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-05 00:21:56 +00:00
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-04 21:28:23 +00:00
|
|
|
pub struct GenericNotEq<T: Eq, U: PartialEq> {
|
2022-05-06 07:10:11 +00:00
|
|
|
foo: T,
|
|
|
|
bar: U,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-04 21:28:23 +00:00
|
|
|
pub struct GenericEq<T: Eq, U: Eq> {
|
2022-05-06 07:10:11 +00:00
|
|
|
foo: T,
|
|
|
|
bar: U,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-04 21:28:23 +00:00
|
|
|
pub struct TupleStruct(u32);
|
2022-05-06 07:10:11 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-04 21:28:23 +00:00
|
|
|
pub struct GenericTupleStruct<T: Eq>(T);
|
2022-05-06 07:10:11 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
2022-06-04 21:28:23 +00:00
|
|
|
pub struct TupleStructNotEq(f32);
|
2022-05-06 07:10:11 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-04 21:28:23 +00:00
|
|
|
pub enum Enum {
|
2022-05-06 07:10:11 +00:00
|
|
|
Foo(u32),
|
|
|
|
Bar { a: String, b: () },
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-04 21:28:23 +00:00
|
|
|
pub enum GenericEnum<T: Eq, U: Eq, V: Eq> {
|
2022-05-06 07:10:11 +00:00
|
|
|
Foo(T),
|
|
|
|
Bar { a: U, b: V },
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
2022-06-04 21:28:23 +00:00
|
|
|
pub enum EnumNotEq {
|
2022-05-06 07:10:11 +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-04 21:28:23 +00:00
|
|
|
pub struct RustFixWithOtherDerives;
|
2022-05-06 07:10:11 +00:00
|
|
|
|
2022-06-05 00:21:56 +00:00
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-04 21:28:23 +00:00
|
|
|
pub struct Generic<T>(T);
|
2022-05-22 16:19:10 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
2022-06-04 21:28:23 +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-05-22 16:19:10 +00:00
|
|
|
|
2022-05-06 07:10:11 +00:00
|
|
|
fn main() {}
|