@@ -4,12 +4,12 @@ use clippy_utils::{
4
4
ty:: implements_trait,
5
5
} ;
6
6
use 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 } ;
8
8
use rustc_hir_analysis:: hir_ty_to_ty;
9
9
use rustc_lint:: { LateContext , LateLintPass } ;
10
10
use rustc_middle:: ty:: EarlyBinder ;
11
11
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
12
- use rustc_span:: { sym, symbol} ;
12
+ use rustc_span:: { sym, symbol:: kw } ;
13
13
use std:: borrow:: Cow ;
14
14
15
15
declare_clippy_lint ! {
@@ -105,8 +105,7 @@ declare_lint_pass!(IncorrectImpls => [INCORRECT_CLONE_IMPL_ON_COPY_TYPE, INCORRE
105
105
impl LateLintPass < ' _ > for IncorrectImpls {
106
106
#[ expect( clippy:: too_many_lines) ]
107
107
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 {
110
109
return ;
111
110
} ;
112
111
let ItemKind :: Impl ( imp) = item. kind else {
@@ -115,7 +114,6 @@ impl LateLintPass<'_> for IncorrectImpls {
115
114
let Some ( trait_impl) = cx. tcx . impl_trait_ref ( item. owner_id ) . map ( EarlyBinder :: skip_binder) else {
116
115
return ;
117
116
} ;
118
- let trait_impl_def_id = trait_impl. def_id ;
119
117
if cx. tcx . is_automatically_derived ( item. owner_id . to_def_id ( ) ) {
120
118
return ;
121
119
}
@@ -127,7 +125,7 @@ impl LateLintPass<'_> for IncorrectImpls {
127
125
return ;
128
126
} ;
129
127
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 )
131
129
&& let Some ( copy_def_id) = cx. tcx . get_diagnostic_item ( sym:: Copy )
132
130
&& implements_trait (
133
131
cx,
@@ -139,9 +137,9 @@ impl LateLintPass<'_> for IncorrectImpls {
139
137
if impl_item. ident . name == sym:: clone {
140
138
if block. stmts . is_empty ( )
141
139
&& 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
145
143
{ } else {
146
144
span_lint_and_sugg (
147
145
cx,
@@ -163,7 +161,7 @@ impl LateLintPass<'_> for IncorrectImpls {
163
161
INCORRECT_CLONE_IMPL_ON_COPY_TYPE ,
164
162
impl_item. span ,
165
163
"incorrect implementation of `clone_from` on a `Copy` type" ,
166
- "remove this " ,
164
+ "remove it " ,
167
165
String :: new ( ) ,
168
166
Applicability :: MaybeIncorrect ,
169
167
) ;
@@ -172,7 +170,7 @@ impl LateLintPass<'_> for IncorrectImpls {
172
170
}
173
171
}
174
172
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 )
176
174
&& impl_item. ident . name == sym:: partial_cmp
177
175
&& let Some ( ord_def_id) = cx
178
176
. tcx
@@ -203,10 +201,7 @@ impl LateLintPass<'_> for IncorrectImpls {
203
201
{ } else {
204
202
// If lhs and rhs are not the same type, bail. This makes creating a valid
205
203
// 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 {
210
205
return ;
211
206
}
212
207
@@ -216,8 +211,8 @@ impl LateLintPass<'_> for IncorrectImpls {
216
211
item. span ,
217
212
"incorrect implementation of `partial_cmp` on an `Ord` type" ,
218
213
|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 ( )
221
216
{
222
217
(
223
218
Cow :: Owned ( format ! ( "{{ Some(self.cmp({})) }}" , other_ident. name) ) ,
0 commit comments