@@ -55,13 +55,13 @@ declare_clippy_lint! {
55
55
/// }
56
56
/// ```
57
57
#[ clippy:: version = "1.72.0" ]
58
- pub NEEDLESS_PARTIAL_ORD_IMPL ,
58
+ pub INCORRECT_PARTIAL_ORD_IMPL_ON_ORD_TYPE ,
59
59
correctness,
60
60
"manual implementation of `PartialOrd` when `Ord` is already implemented"
61
61
}
62
- declare_lint_pass ! ( NeedlessImpls => [ NEEDLESS_PARTIAL_ORD_IMPL ] ) ;
62
+ declare_lint_pass ! ( IncorrectImpls => [ INCORRECT_PARTIAL_ORD_IMPL_ON_ORD_TYPE ] ) ;
63
63
64
- impl LateLintPass < ' _ > for NeedlessImpls {
64
+ impl LateLintPass < ' _ > for IncorrectImpls {
65
65
fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , impl_item : & ImplItem < ' _ > ) {
66
66
let node = get_parent_node ( cx. tcx , impl_item. hir_id ( ) ) ;
67
67
let Some ( Node :: Item ( item) ) = node else {
@@ -114,13 +114,22 @@ impl LateLintPass<'_> for NeedlessImpls {
114
114
&& cmp_path. ident . name == sym:: cmp
115
115
&& let Res :: Local ( ..) = path_res ( cx, other_expr)
116
116
{ } else {
117
+ // If lhs and rhs are not the same type, bail. This makes creating a valid
118
+ // suggestion tons more complex.
119
+ if let Some ( lhs) = trait_impl. substs . get ( 0 )
120
+ && let Some ( rhs) = trait_impl. substs . get ( 1 )
121
+ && lhs != rhs
122
+ {
123
+ return ;
124
+ }
125
+
117
126
span_lint_and_then (
118
127
cx,
119
- NEEDLESS_PARTIAL_ORD_IMPL ,
128
+ INCORRECT_PARTIAL_ORD_IMPL_ON_ORD_TYPE ,
120
129
item. span ,
121
- "manual implementation of `PartialOrd` when `Ord` is already implemented " ,
130
+ "incorrect implementation of `partial_cmp` on an `Ord` type " ,
122
131
|diag| {
123
- let ( help, app) = if let Some ( other) = body. params . get ( 0 )
132
+ let ( help, app) = if let Some ( other) = body. params . get ( 1 )
124
133
&& let PatKind :: Binding ( _, _, other_ident, ..) = other. pat . kind
125
134
{
126
135
(
0 commit comments