@@ -4,8 +4,9 @@ use clippy_utils::ty::implements_trait;
4
4
use hir:: { ImplItem , Item } ;
5
5
use rustc_hir as hir;
6
6
use rustc_lint:: { LateContext , LateLintPass } ;
7
+ use rustc_middle:: ty;
7
8
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
8
- use rustc_span:: def_id:: LocalDefId ;
9
+ use rustc_span:: def_id:: DefId ;
9
10
use rustc_span:: symbol:: Ident ;
10
11
11
12
declare_clippy_lint ! {
@@ -72,9 +73,9 @@ declare_clippy_lint! {
72
73
#[ derive( Clone ) ]
73
74
pub struct AmbiguousMethodNames {
74
75
// Keeps track of trait methods
75
- trait_methods : Vec < ( LocalDefId , Ident ) > ,
76
+ trait_methods : Vec < ( DefId , Ident ) > ,
76
77
// Keeps track of inherent methods
77
- inherent_methods : Vec < ( LocalDefId , Ident ) > ,
78
+ inherent_methods : Vec < ( DefId , Ident ) > ,
78
79
}
79
80
80
81
impl AmbiguousMethodNames {
@@ -94,7 +95,8 @@ impl<'tcx> LateLintPass<'tcx> for AmbiguousMethodNames {
94
95
if let hir:: ItemKind :: Trait ( _, _, _, _, tr_items) = item. kind {
95
96
for tr_item in tr_items {
96
97
if let hir:: AssocItemKind :: Fn { .. } = tr_item. kind {
97
- self . trait_methods . push ( ( item. owner_id . def_id , tr_item. ident ) )
98
+ self . trait_methods
99
+ . push ( ( item. owner_id . def_id . to_def_id ( ) , tr_item. ident ) ) ;
98
100
}
99
101
}
100
102
}
@@ -106,16 +108,25 @@ impl<'tcx> LateLintPass<'tcx> for AmbiguousMethodNames {
106
108
let hir_id = cx. tcx . hir ( ) . local_def_id_to_hir_id ( impl_item. owner_id . def_id ) ;
107
109
if !is_trait_impl_item ( cx, hir_id) {
108
110
let struct_id = cx. tcx . hir ( ) . get_parent_item ( hir_id) ;
109
- self . inherent_methods . push ( ( struct_id. def_id , impl_item. ident ) )
111
+ self . inherent_methods
112
+ . push ( ( struct_id. def_id . to_def_id ( ) , impl_item. ident ) ) ;
110
113
}
111
114
}
112
115
}
113
116
114
117
fn check_crate_post ( & mut self , cx : & LateContext < ' tcx > ) {
115
118
for ( r#trait, ident) in & self . trait_methods {
116
119
for ( r#struct, inherent_ident) in & self . inherent_methods {
117
- let struct_ty = cx. tcx . type_of ( r#struct. to_def_id ( ) ) . skip_binder ( ) ;
118
- if implements_trait ( cx, struct_ty, r#trait. to_def_id ( ) , & [ ] ) && ident. name == inherent_ident. name {
120
+ let struct_ty = cx. tcx . type_of ( r#struct) . skip_binder ( ) ;
121
+ let trait_ref = ty:: TraitRef :: identity ( cx. tcx , * r#trait) ;
122
+ let args = & trait_ref. args [ 1 ..] ;
123
+ if implements_trait (
124
+ cx,
125
+ struct_ty,
126
+ * r#trait,
127
+ & args[ ..cx. tcx . generics_of ( r#trait) . params . len ( ) - 1 ] ,
128
+ ) && ident. name == inherent_ident. name
129
+ {
119
130
span_lint_and_note (
120
131
cx,
121
132
AMBIGUOUS_METHOD_NAMES ,
0 commit comments