@@ -4,8 +4,9 @@ use clippy_utils::ty::implements_trait;
44use hir:: { ImplItem , Item } ;
55use rustc_hir as hir;
66use rustc_lint:: { LateContext , LateLintPass } ;
7+ use rustc_middle:: ty;
78use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
8- use rustc_span:: def_id:: LocalDefId ;
9+ use rustc_span:: def_id:: DefId ;
910use rustc_span:: symbol:: Ident ;
1011
1112declare_clippy_lint ! {
@@ -72,9 +73,9 @@ declare_clippy_lint! {
7273#[ derive( Clone ) ]
7374pub struct AmbiguousMethodNames {
7475 // Keeps track of trait methods
75- trait_methods : Vec < ( LocalDefId , Ident ) > ,
76+ trait_methods : Vec < ( DefId , Ident ) > ,
7677 // Keeps track of inherent methods
77- inherent_methods : Vec < ( LocalDefId , Ident ) > ,
78+ inherent_methods : Vec < ( DefId , Ident ) > ,
7879}
7980
8081impl AmbiguousMethodNames {
@@ -94,7 +95,8 @@ impl<'tcx> LateLintPass<'tcx> for AmbiguousMethodNames {
9495 if let hir:: ItemKind :: Trait ( _, _, _, _, tr_items) = item. kind {
9596 for tr_item in tr_items {
9697 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 ) ) ;
98100 }
99101 }
100102 }
@@ -106,16 +108,25 @@ impl<'tcx> LateLintPass<'tcx> for AmbiguousMethodNames {
106108 let hir_id = cx. tcx . hir ( ) . local_def_id_to_hir_id ( impl_item. owner_id . def_id ) ;
107109 if !is_trait_impl_item ( cx, hir_id) {
108110 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 ) ) ;
110113 }
111114 }
112115 }
113116
114117 fn check_crate_post ( & mut self , cx : & LateContext < ' tcx > ) {
115118 for ( r#trait, ident) in & self . trait_methods {
116119 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+ {
119130 span_lint_and_note (
120131 cx,
121132 AMBIGUOUS_METHOD_NAMES ,
0 commit comments