@@ -55,13 +55,13 @@ declare_clippy_lint! {
5555 /// }
5656 /// ```
5757 #[ clippy:: version = "1.72.0" ]
58- pub NEEDLESS_PARTIAL_ORD_IMPL ,
58+ pub INCORRECT_PARTIAL_ORD_IMPL_ON_ORD_TYPE ,
5959 correctness,
6060 "manual implementation of `PartialOrd` when `Ord` is already implemented"
6161}
62- declare_lint_pass ! ( NeedlessImpls => [ NEEDLESS_PARTIAL_ORD_IMPL ] ) ;
62+ declare_lint_pass ! ( IncorrectImpls => [ INCORRECT_PARTIAL_ORD_IMPL_ON_ORD_TYPE ] ) ;
6363
64- impl LateLintPass < ' _ > for NeedlessImpls {
64+ impl LateLintPass < ' _ > for IncorrectImpls {
6565 fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , impl_item : & ImplItem < ' _ > ) {
6666 let node = get_parent_node ( cx. tcx , impl_item. hir_id ( ) ) ;
6767 let Some ( Node :: Item ( item) ) = node else {
@@ -114,13 +114,22 @@ impl LateLintPass<'_> for NeedlessImpls {
114114 && cmp_path. ident . name == sym:: cmp
115115 && let Res :: Local ( ..) = path_res ( cx, other_expr)
116116 { } 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+
117126 span_lint_and_then (
118127 cx,
119- NEEDLESS_PARTIAL_ORD_IMPL ,
128+ INCORRECT_PARTIAL_ORD_IMPL_ON_ORD_TYPE ,
120129 item. span ,
121- "manual implementation of `PartialOrd` when `Ord` is already implemented " ,
130+ "incorrect implementation of `partial_cmp` on an `Ord` type " ,
122131 |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 )
124133 && let PatKind :: Binding ( _, _, other_ident, ..) = other. pat . kind
125134 {
126135 (
0 commit comments