diff options
Diffstat (limited to 'crates/ra_assists')
-rw-r--r-- | crates/ra_assists/src/utils.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs index 7bc21c6e4..660da3645 100644 --- a/crates/ra_assists/src/utils.rs +++ b/crates/ra_assists/src/utils.rs | |||
@@ -9,24 +9,25 @@ use hir::db::HirDatabase; | |||
9 | 9 | ||
10 | use rustc_hash::FxHashSet; | 10 | use rustc_hash::FxHashSet; |
11 | 11 | ||
12 | /// Generate a collection of associated items that are missing from a | ||
13 | /// `impl Trait for` block. | ||
12 | pub fn get_missing_impl_items( | 14 | pub fn get_missing_impl_items( |
13 | db: &impl HirDatabase, | 15 | db: &impl HirDatabase, |
14 | analyzer: &hir::SourceAnalyzer, | 16 | analyzer: &hir::SourceAnalyzer, |
15 | impl_block: &ast::ImplBlock, | 17 | impl_block: &ast::ImplBlock, |
16 | ) -> Vec<hir::AssocItem> { | 18 | ) -> Vec<hir::AssocItem> { |
17 | // since the names are unique only to each associated type (fn/type/const), | 19 | |
18 | // create buckets of each already implemented type that we'll use in the | 20 | // Names must be unique between constants and functions. However, type aliases |
19 | // lookup later. | 21 | // may share the same name as a function or constant. |
20 | let mut impl_fns = FxHashSet::default(); | 22 | let mut impl_fns_consts = FxHashSet::default(); |
21 | let mut impl_type = FxHashSet::default(); | 23 | let mut impl_type = FxHashSet::default(); |
22 | let mut impl_const = FxHashSet::default(); | ||
23 | 24 | ||
24 | if let Some(item_list) = impl_block.item_list() { | 25 | if let Some(item_list) = impl_block.item_list() { |
25 | for item in item_list.impl_items() { | 26 | for item in item_list.impl_items() { |
26 | match item { | 27 | match item { |
27 | ast::ImplItem::FnDef(f) => { | 28 | ast::ImplItem::FnDef(f) => { |
28 | if let Some(n) = f.name() { | 29 | if let Some(n) = f.name() { |
29 | impl_fns.insert(n.syntax().to_string()); | 30 | impl_fns_consts.insert(n.syntax().to_string()); |
30 | } | 31 | } |
31 | } | 32 | } |
32 | 33 | ||
@@ -38,7 +39,7 @@ pub fn get_missing_impl_items( | |||
38 | 39 | ||
39 | ast::ImplItem::ConstDef(c) => { | 40 | ast::ImplItem::ConstDef(c) => { |
40 | if let Some(n) = c.name() { | 41 | if let Some(n) = c.name() { |
41 | impl_const.insert(n.syntax().to_string()); | 42 | impl_fns_consts.insert(n.syntax().to_string()); |
42 | } | 43 | } |
43 | } | 44 | } |
44 | } | 45 | } |
@@ -50,10 +51,10 @@ pub fn get_missing_impl_items( | |||
50 | .items(db) | 51 | .items(db) |
51 | .iter() | 52 | .iter() |
52 | .filter(|i| match i { | 53 | .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()), |
54 | hir::AssocItem::TypeAlias(t) => !impl_type.contains(&t.name(db).to_string()), | 55 | hir::AssocItem::TypeAlias(t) => !impl_type.contains(&t.name(db).to_string()), |
55 | hir::AssocItem::Const(c) => { | 56 | 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() |
57 | } | 58 | } |
58 | }) | 59 | }) |
59 | .map(|i| i.clone()) | 60 | .map(|i| i.clone()) |