@@ -6,7 +6,9 @@ use rustc::ty::{self, Ty};
6
6
use rustc:: { declare_lint_pass, declare_tool_lint} ;
7
7
use rustc_errors:: Applicability ;
8
8
9
- use crate :: utils:: { is_adjusted, iter_input_pats, snippet_opt, span_lint_and_then, type_is_unsafe_function} ;
9
+ use crate :: utils:: {
10
+ implements_trait, is_adjusted, iter_input_pats, snippet_opt, span_lint_and_then, type_is_unsafe_function,
11
+ } ;
10
12
11
13
declare_clippy_lint ! {
12
14
/// **What it does:** Checks for closures which just call another function where
@@ -152,7 +154,9 @@ fn get_ufcs_type_name(
152
154
let actual_type_of_self = & cx. tables . node_type ( self_arg. hir_id ) ;
153
155
154
156
if let Some ( trait_id) = cx. tcx . trait_of_item ( method_def_id) {
155
- if match_borrow_depth ( expected_type_of_self, & actual_type_of_self) {
157
+ if match_borrow_depth ( expected_type_of_self, & actual_type_of_self)
158
+ && implements_trait ( cx, actual_type_of_self, trait_id, & [ ] )
159
+ {
156
160
return Some ( cx. tcx . def_path_str ( trait_id) ) ;
157
161
}
158
162
}
@@ -168,7 +172,7 @@ fn get_ufcs_type_name(
168
172
169
173
fn match_borrow_depth ( lhs : Ty < ' _ > , rhs : Ty < ' _ > ) -> bool {
170
174
match ( & lhs. sty , & rhs. sty ) {
171
- ( ty:: Ref ( _, t1, _ ) , ty:: Ref ( _, t2, _ ) ) => match_borrow_depth ( & t1, & t2) ,
175
+ ( ty:: Ref ( _, t1, mut1 ) , ty:: Ref ( _, t2, mut2 ) ) => mut1 == mut2 && match_borrow_depth ( & t1, & t2) ,
172
176
( l, r) => match ( l, r) {
173
177
( ty:: Ref ( _, _, _) , _) | ( _, ty:: Ref ( _, _, _) ) => false ,
174
178
( _, _) => true ,
@@ -183,9 +187,8 @@ fn match_types(lhs: Ty<'_>, rhs: Ty<'_>) -> bool {
183
187
| ( ty:: Int ( _) , ty:: Int ( _) )
184
188
| ( ty:: Uint ( _) , ty:: Uint ( _) )
185
189
| ( ty:: Str , ty:: Str ) => true ,
186
- ( ty:: Ref ( _, t1, _) , ty:: Ref ( _, t2, _) )
187
- | ( ty:: Array ( t1, _) , ty:: Array ( t2, _) )
188
- | ( ty:: Slice ( t1) , ty:: Slice ( t2) ) => match_types ( t1, t2) ,
190
+ ( ty:: Ref ( _, t1, mut1) , ty:: Ref ( _, t2, mut2) ) => mut1 == mut2 && match_types ( t1, t2) ,
191
+ ( ty:: Array ( t1, _) , ty:: Array ( t2, _) ) | ( ty:: Slice ( t1) , ty:: Slice ( t2) ) => match_types ( t1, t2) ,
189
192
( ty:: Adt ( def1, _) , ty:: Adt ( def2, _) ) => def1 == def2,
190
193
( _, _) => false ,
191
194
}
0 commit comments