22
33use std:: ops:: ControlFlow ;
44
5- use hir:: { Complete , HasContainer , ItemContainer , MethodCandidateCallback , Name } ;
5+ use hir:: { Complete , Function , HasContainer , ItemContainer , MethodCandidateCallback } ;
66use ide_db:: FxHashSet ;
77use syntax:: SmolStr ;
88
@@ -237,7 +237,10 @@ fn complete_methods(
237237 struct Callback < ' a , F > {
238238 ctx : & ' a CompletionContext < ' a > ,
239239 f : F ,
240- seen_methods : FxHashSet < Name > ,
240+ // We deliberately deduplicate by function ID and not name, because while inherent methods cannot be
241+ // duplicated, trait methods can. And it is still useful to show all of them (even when there
242+ // is also an inherent method, especially considering that it may be private, and filtered later).
243+ seen_methods : FxHashSet < Function > ,
241244 }
242245
243246 impl < F > MethodCandidateCallback for Callback < ' _ , F >
@@ -247,9 +250,7 @@ fn complete_methods(
247250 // We don't want to exclude inherent trait methods - that is, methods of traits available from
248251 // `where` clauses or `dyn Trait`.
249252 fn on_inherent_method ( & mut self , func : hir:: Function ) -> ControlFlow < ( ) > {
250- if func. self_param ( self . ctx . db ) . is_some ( )
251- && self . seen_methods . insert ( func. name ( self . ctx . db ) )
252- {
253+ if func. self_param ( self . ctx . db ) . is_some ( ) && self . seen_methods . insert ( func) {
253254 ( self . f ) ( func) ;
254255 }
255256 ControlFlow :: Continue ( ( ) )
@@ -265,9 +266,7 @@ fn complete_methods(
265266 return ControlFlow :: Continue ( ( ) ) ;
266267 }
267268
268- if func. self_param ( self . ctx . db ) . is_some ( )
269- && self . seen_methods . insert ( func. name ( self . ctx . db ) )
270- {
269+ if func. self_param ( self . ctx . db ) . is_some ( ) && self . seen_methods . insert ( func) {
271270 ( self . f ) ( func) ;
272271 }
273272
0 commit comments