@@ -9,24 +9,25 @@ use hir::db::HirDatabase;
99
1010use rustc_hash:: FxHashSet ;
1111
12+ /// Generate a collection of associated items that are missing from a
13+ /// `impl Trait for` block.
1214pub fn get_missing_impl_items (
1315 db : & impl HirDatabase ,
1416 analyzer : & hir:: SourceAnalyzer ,
1517 impl_block : & ast:: ImplBlock ,
1618) -> Vec < hir:: AssocItem > {
17- // since the names are unique only to each associated type (fn/type/const),
18- // create buckets of each already implemented type that we'll use in the
19- // lookup later .
20- let mut impl_fns = FxHashSet :: default ( ) ;
19+
20+ // Names must be unique between constants and functions. However, type aliases
21+ // may share the same name as a function or constant .
22+ let mut impl_fns_consts = FxHashSet :: default ( ) ;
2123 let mut impl_type = FxHashSet :: default ( ) ;
22- let mut impl_const = FxHashSet :: default ( ) ;
2324
2425 if let Some ( item_list) = impl_block. item_list ( ) {
2526 for item in item_list. impl_items ( ) {
2627 match item {
2728 ast:: ImplItem :: FnDef ( f) => {
2829 if let Some ( n) = f. name ( ) {
29- impl_fns . insert ( n. syntax ( ) . to_string ( ) ) ;
30+ impl_fns_consts . insert ( n. syntax ( ) . to_string ( ) ) ;
3031 }
3132 }
3233
@@ -38,7 +39,7 @@ pub fn get_missing_impl_items(
3839
3940 ast:: ImplItem :: ConstDef ( c) => {
4041 if let Some ( n) = c. name ( ) {
41- impl_const . insert ( n. syntax ( ) . to_string ( ) ) ;
42+ impl_fns_consts . insert ( n. syntax ( ) . to_string ( ) ) ;
4243 }
4344 }
4445 }
@@ -50,10 +51,10 @@ pub fn get_missing_impl_items(
5051 . items ( db)
5152 . iter ( )
5253 . filter ( |i| match i {
53- hir:: AssocItem :: Function ( f) => !impl_fns . contains ( & f. name ( db) . to_string ( ) ) ,
54+ hir:: AssocItem :: Function ( f) => !impl_fns_consts . contains ( & f. name ( db) . to_string ( ) ) ,
5455 hir:: AssocItem :: TypeAlias ( t) => !impl_type. contains ( & t. name ( db) . to_string ( ) ) ,
5556 hir:: AssocItem :: Const ( c) => {
56- c. name ( db) . map ( |n| !impl_const . contains ( & n. to_string ( ) ) ) . unwrap_or_default ( )
57+ c. name ( db) . map ( |n| !impl_fns_consts . contains ( & n. to_string ( ) ) ) . unwrap_or_default ( )
5758 }
5859 } )
5960 . map ( |i| i. clone ( ) )
0 commit comments