@@ -4,12 +4,12 @@ use clippy_utils::{
44 ty:: implements_trait,
55} ;
66use rustc_errors:: Applicability ;
7- use rustc_hir:: { def:: Res , Expr , ExprKind , ImplItem , ImplItemKind , ItemKind , LangItem , Node , PatKind , UnOp } ;
7+ use rustc_hir:: { def:: Res , Expr , ExprKind , ImplItem , ImplItemKind , ItemKind , LangItem , Node , UnOp } ;
88use rustc_hir_analysis:: hir_ty_to_ty;
99use rustc_lint:: { LateContext , LateLintPass } ;
1010use rustc_middle:: ty:: EarlyBinder ;
1111use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
12- use rustc_span:: { sym, symbol} ;
12+ use rustc_span:: { sym, symbol:: kw } ;
1313use std:: borrow:: Cow ;
1414
1515declare_clippy_lint ! {
@@ -105,8 +105,7 @@ declare_lint_pass!(IncorrectImpls => [INCORRECT_CLONE_IMPL_ON_COPY_TYPE, INCORRE
105105impl LateLintPass < ' _ > for IncorrectImpls {
106106 #[ expect( clippy:: too_many_lines) ]
107107 fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , impl_item : & ImplItem < ' _ > ) {
108- let node = get_parent_node ( cx. tcx , impl_item. hir_id ( ) ) ;
109- let Some ( Node :: Item ( item) ) = node else {
108+ let Some ( Node :: Item ( item) ) = get_parent_node ( cx. tcx , impl_item. hir_id ( ) ) else {
110109 return ;
111110 } ;
112111 let ItemKind :: Impl ( imp) = item. kind else {
@@ -115,7 +114,6 @@ impl LateLintPass<'_> for IncorrectImpls {
115114 let Some ( trait_impl) = cx. tcx . impl_trait_ref ( item. owner_id ) . map ( EarlyBinder :: skip_binder) else {
116115 return ;
117116 } ;
118- let trait_impl_def_id = trait_impl. def_id ;
119117 if cx. tcx . is_automatically_derived ( item. owner_id . to_def_id ( ) ) {
120118 return ;
121119 }
@@ -127,7 +125,7 @@ impl LateLintPass<'_> for IncorrectImpls {
127125 return ;
128126 } ;
129127
130- if cx. tcx . is_diagnostic_item ( sym:: Clone , trait_impl_def_id )
128+ if cx. tcx . is_diagnostic_item ( sym:: Clone , trait_impl . def_id )
131129 && let Some ( copy_def_id) = cx. tcx . get_diagnostic_item ( sym:: Copy )
132130 && implements_trait (
133131 cx,
@@ -139,9 +137,9 @@ impl LateLintPass<'_> for IncorrectImpls {
139137 if impl_item. ident . name == sym:: clone {
140138 if block. stmts . is_empty ( )
141139 && let Some ( expr) = block. expr
142- && let ExprKind :: Unary ( UnOp :: Deref , inner ) = expr. kind
143- && let ExprKind :: Path ( qpath) = inner . kind
144- && last_path_segment ( & qpath) . ident . name == symbol :: kw:: SelfLower
140+ && let ExprKind :: Unary ( UnOp :: Deref , deref ) = expr. kind
141+ && let ExprKind :: Path ( qpath) = deref . kind
142+ && last_path_segment ( & qpath) . ident . name == kw:: SelfLower
145143 { } else {
146144 span_lint_and_sugg (
147145 cx,
@@ -163,7 +161,7 @@ impl LateLintPass<'_> for IncorrectImpls {
163161 INCORRECT_CLONE_IMPL_ON_COPY_TYPE ,
164162 impl_item. span ,
165163 "incorrect implementation of `clone_from` on a `Copy` type" ,
166- "remove this " ,
164+ "remove it " ,
167165 String :: new ( ) ,
168166 Applicability :: MaybeIncorrect ,
169167 ) ;
@@ -172,7 +170,7 @@ impl LateLintPass<'_> for IncorrectImpls {
172170 }
173171 }
174172
175- if cx. tcx . is_diagnostic_item ( sym:: PartialOrd , trait_impl_def_id )
173+ if cx. tcx . is_diagnostic_item ( sym:: PartialOrd , trait_impl . def_id )
176174 && impl_item. ident . name == sym:: partial_cmp
177175 && let Some ( ord_def_id) = cx
178176 . tcx
@@ -203,10 +201,7 @@ impl LateLintPass<'_> for IncorrectImpls {
203201 { } else {
204202 // If lhs and rhs are not the same type, bail. This makes creating a valid
205203 // suggestion tons more complex.
206- if let Some ( lhs) = trait_impl. substs . get ( 0 )
207- && let Some ( rhs) = trait_impl. substs . get ( 1 )
208- && lhs != rhs
209- {
204+ if let [ lhs, rhs, ..] = trait_impl. substs . as_slice ( ) && lhs != rhs {
210205 return ;
211206 }
212207
@@ -216,8 +211,8 @@ impl LateLintPass<'_> for IncorrectImpls {
216211 item. span ,
217212 "incorrect implementation of `partial_cmp` on an `Ord` type" ,
218213 |diag| {
219- let ( help, app) = if let Some ( other) = body. params . get ( 1 )
220- && let PatKind :: Binding ( _ , _ , other_ident, .. ) = other. pat . kind
214+ let ( help, app) = if let [ _ , other] = body. params
215+ && let Some ( other_ident) = other. pat . simple_ident ( )
221216 {
222217 (
223218 Cow :: Owned ( format ! ( "{{ Some(self.cmp({})) }}" , other_ident. name) ) ,
0 commit comments