]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/derive_partial_eq_without_eq.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / tools / clippy / 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 pub struct NotPartialEq {
8 foo: u32,
9 bar: String,
10 }
11
12 // Eq can be derived but is missing
13 #[derive(Debug, PartialEq)]
14 pub struct MissingEq {
15 foo: u32,
16 bar: String,
17 }
18
19 // Eq is derived
20 #[derive(PartialEq, Eq)]
21 pub struct NotMissingEq {
22 foo: u32,
23 bar: String,
24 }
25
26 // Eq is manually implemented
27 #[derive(PartialEq)]
28 pub 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 pub struct CannotBeEq {
38 foo: u32,
39 bar: f32,
40 }
41
42 // Don't warn if PartialEq is manually implemented
43 pub 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 pub struct GenericNotEq<T: Eq, U: PartialEq> {
57 foo: T,
58 bar: U,
59 }
60
61 #[derive(PartialEq)]
62 pub struct GenericEq<T: Eq, U: Eq> {
63 foo: T,
64 bar: U,
65 }
66
67 #[derive(PartialEq)]
68 pub struct TupleStruct(u32);
69
70 #[derive(PartialEq)]
71 pub struct GenericTupleStruct<T: Eq>(T);
72
73 #[derive(PartialEq)]
74 pub struct TupleStructNotEq(f32);
75
76 #[derive(PartialEq)]
77 pub enum Enum {
78 Foo(u32),
79 Bar { a: String, b: () },
80 }
81
82 #[derive(PartialEq)]
83 pub enum GenericEnum<T: Eq, U: Eq, V: Eq> {
84 Foo(T),
85 Bar { a: U, b: V },
86 }
87
88 #[derive(PartialEq)]
89 pub 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 pub struct RustFixWithOtherDerives;
97
98 #[derive(PartialEq)]
99 pub struct Generic<T>(T);
100
101 #[derive(PartialEq, Eq)]
102 pub struct GenericPhantom<T>(core::marker::PhantomData<T>);
103
104 mod _hidden {
105 #[derive(PartialEq)]
106 pub struct Reexported;
107
108 #[derive(PartialEq)]
109 pub struct InPubFn;
110
111 #[derive(PartialEq)]
112 pub(crate) struct PubCrate;
113
114 #[derive(PartialEq)]
115 pub(super) struct PubSuper;
116 }
117
118 pub use _hidden::Reexported;
119 pub fn _from_mod() -> _hidden::InPubFn {
120 _hidden::InPubFn
121 }
122
123 #[derive(PartialEq)]
124 struct InternalTy;
125
126 fn main() {}