2
2
3
3
use std:: ops:: ControlFlow ;
4
4
5
- use hir:: { Complete , HasContainer , ItemContainer , MethodCandidateCallback , Name } ;
5
+ use hir:: { Complete , Function , HasContainer , ItemContainer , MethodCandidateCallback } ;
6
6
use ide_db:: FxHashSet ;
7
7
use syntax:: SmolStr ;
8
8
@@ -237,7 +237,10 @@ fn complete_methods(
237
237
struct Callback < ' a , F > {
238
238
ctx : & ' a CompletionContext < ' a > ,
239
239
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 > ,
241
244
}
242
245
243
246
impl < F > MethodCandidateCallback for Callback < ' _ , F >
@@ -247,9 +250,7 @@ fn complete_methods(
247
250
// We don't want to exclude inherent trait methods - that is, methods of traits available from
248
251
// `where` clauses or `dyn Trait`.
249
252
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) {
253
254
( self . f ) ( func) ;
254
255
}
255
256
ControlFlow :: Continue ( ( ) )
@@ -265,9 +266,7 @@ fn complete_methods(
265
266
return ControlFlow :: Continue ( ( ) ) ;
266
267
}
267
268
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) {
271
270
( self . f ) ( func) ;
272
271
}
273
272
0 commit comments