]> git.lizzy.rs Git - rust.git/blob - tests/ui/derive_partial_eq_without_eq.rs
Auto merge of #8848 - Serial-ATA:auto-detect-theme, r=xFrednet
[rust.git] / tests / ui / derive_partial_eq_without_eq.rs
1 // run-rustfix
2
3 #![allow(unused)]
4 #![warn(clippy::derive_partial_eq_without_eq)]
5
6 // Don't warn on structs that aren't PartialEq
7 struct NotPartialEq {
8     foo: u32,
9     bar: String,
10 }
11
12 // Eq can be derived but is missing
13 #[derive(Debug, PartialEq)]
14 struct MissingEq {
15     foo: u32,
16     bar: String,
17 }
18
19 // Eq is derived
20 #[derive(PartialEq, Eq)]
21 struct NotMissingEq {
22     foo: u32,
23     bar: String,
24 }
25
26 // Eq is manually implemented
27 #[derive(PartialEq)]
28 struct ManualEqImpl {
29     foo: u32,
30     bar: String,
31 }
32
33 impl Eq for ManualEqImpl {}
34
35 // Cannot be Eq because f32 isn't Eq
36 #[derive(PartialEq)]
37 struct CannotBeEq {
38     foo: u32,
39     bar: f32,
40 }
41
42 // Don't warn if PartialEq is manually implemented
43 struct ManualPartialEqImpl {
44     foo: u32,
45     bar: String,
46 }
47
48 impl PartialEq for ManualPartialEqImpl {
49     fn eq(&self, other: &Self) -> bool {
50         self.foo == other.foo && self.bar == other.bar
51     }
52 }
53
54 // Generic fields should be properly checked for Eq-ness
55 #[derive(PartialEq)]
56 struct GenericNotEq<T: Eq, U: PartialEq> {
57     foo: T,
58     bar: U,
59 }
60
61 #[derive(PartialEq)]
62 struct GenericEq<T: Eq, U: Eq> {
63     foo: T,
64     bar: U,
65 }
66
67 #[derive(PartialEq)]
68 struct TupleStruct(u32);
69
70 #[derive(PartialEq)]
71 struct GenericTupleStruct<T: Eq>(T);
72
73 #[derive(PartialEq)]
74 struct TupleStructNotEq(f32);
75
76 #[derive(PartialEq)]
77 enum Enum {
78     Foo(u32),
79     Bar { a: String, b: () },
80 }
81
82 #[derive(PartialEq)]
83 enum GenericEnum<T: Eq, U: Eq, V: Eq> {
84     Foo(T),
85     Bar { a: U, b: V },
86 }
87
88 #[derive(PartialEq)]
89 enum EnumNotEq {
90     Foo(u32),
91     Bar { a: String, b: f32 },
92 }
93
94 // Ensure that rustfix works properly when `PartialEq` has other derives on either side
95 #[derive(Debug, PartialEq, Clone)]
96 struct RustFixWithOtherDerives;
97
98 fn main() {}