@@ -164,12 +164,14 @@ declare_clippy_lint! {
164
164
165
165
pub struct CopyAndPaste {
166
166
ignore_interior_mutability : Vec < String > ,
167
+ ignored_ty_ids : FxHashSet < DefId > ,
167
168
}
168
169
169
170
impl CopyAndPaste {
170
171
pub fn new ( ignore_interior_mutability : Vec < String > ) -> Self {
171
172
Self {
172
173
ignore_interior_mutability,
174
+ ignored_ty_ids : FxHashSet :: default ( ) ,
173
175
}
174
176
}
175
177
}
@@ -182,17 +184,18 @@ impl_lint_pass!(CopyAndPaste => [
182
184
] ) ;
183
185
184
186
impl < ' tcx > LateLintPass < ' tcx > for CopyAndPaste {
187
+ fn check_crate ( & mut self , cx : & LateContext < ' tcx > ) {
188
+ for ignored_ty in & self . ignore_interior_mutability {
189
+ let path: Vec < & str > = ignored_ty. split ( "::" ) . collect ( ) ;
190
+ for id in def_path_def_ids ( cx, path. as_slice ( ) ) {
191
+ self . ignored_ty_ids . insert ( id) ;
192
+ }
193
+ }
194
+ }
185
195
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' _ > ) {
186
196
if !expr. span . from_expansion ( ) && matches ! ( expr. kind, ExprKind :: If ( ..) ) && !is_else_clause ( cx. tcx , expr) {
187
197
let ( conds, blocks) = if_sequence ( expr) ;
188
- let mut ignored_ty_ids = FxHashSet :: default ( ) ;
189
- for ignored_ty in & self . ignore_interior_mutability {
190
- let path: Vec < & str > = ignored_ty. split ( "::" ) . collect ( ) ;
191
- for id in def_path_def_ids ( cx, path. as_slice ( ) ) {
192
- ignored_ty_ids. insert ( id) ;
193
- }
194
- }
195
- lint_same_cond ( cx, & conds, & ignored_ty_ids) ;
198
+ lint_same_cond ( cx, & conds, & self . ignored_ty_ids ) ;
196
199
lint_same_fns_in_if_cond ( cx, & conds) ;
197
200
let all_same =
198
201
!is_lint_allowed ( cx, IF_SAME_THEN_ELSE , expr. hir_id ) && lint_if_same_then_else ( cx, & conds, & blocks) ;
@@ -575,22 +578,12 @@ fn method_caller_is_ignored_or_mutable(
575
578
ignored_ty_ids : & FxHashSet < DefId > ,
576
579
) -> bool {
577
580
let caller_ty = cx. typeck_results ( ) . expr_ty ( caller_expr) ;
578
- let is_ignored_ty = if let Some ( adt_id) = caller_ty. ty_adt_id ( ) && ignored_ty_ids. contains ( & adt_id) {
579
- true
580
- } else {
581
- false
582
- } ;
583
-
584
- if is_ignored_ty
581
+ matches ! ( caller_ty. ty_adt_id( ) , Some ( adt_id) if ignored_ty_ids. contains( & adt_id) )
585
582
|| caller_ty. is_mutable_ptr ( )
583
+ // Check if a binding is mutable or not
586
584
|| path_to_local ( caller_expr)
587
585
. and_then ( |hid| find_binding_init ( cx, hid) )
588
586
. is_none ( )
589
- {
590
- return true ;
591
- }
592
-
593
- false
594
587
}
595
588
596
589
/// Implementation of `IFS_SAME_COND`.
0 commit comments