From f0f242cb4f9ee49427b03af21c31239e8132ac96 Mon Sep 17 00:00:00 2001 From: Kevin DeLorey <2295721+kdelorey@users.noreply.github.com> Date: Mon, 10 Feb 2020 21:09:04 -0600 Subject: Adjusted the hashset buckets to lump functions/consts together as their names must be unique. --- crates/ra_assists/src/utils.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'crates') 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; use rustc_hash::FxHashSet; +/// Generate a collection of associated items that are missing from a +/// `impl Trait for` block. pub fn get_missing_impl_items( db: &impl HirDatabase, analyzer: &hir::SourceAnalyzer, impl_block: &ast::ImplBlock, ) -> Vec { - // since the names are unique only to each associated type (fn/type/const), - // create buckets of each already implemented type that we'll use in the - // lookup later. - let mut impl_fns = FxHashSet::default(); + + // Names must be unique between constants and functions. However, type aliases + // may share the same name as a function or constant. + let mut impl_fns_consts = FxHashSet::default(); let mut impl_type = FxHashSet::default(); - let mut impl_const = FxHashSet::default(); if let Some(item_list) = impl_block.item_list() { for item in item_list.impl_items() { match item { ast::ImplItem::FnDef(f) => { if let Some(n) = f.name() { - impl_fns.insert(n.syntax().to_string()); + impl_fns_consts.insert(n.syntax().to_string()); } } @@ -38,7 +39,7 @@ pub fn get_missing_impl_items( ast::ImplItem::ConstDef(c) => { if let Some(n) = c.name() { - impl_const.insert(n.syntax().to_string()); + impl_fns_consts.insert(n.syntax().to_string()); } } } @@ -50,10 +51,10 @@ pub fn get_missing_impl_items( .items(db) .iter() .filter(|i| match i { - hir::AssocItem::Function(f) => !impl_fns.contains(&f.name(db).to_string()), + hir::AssocItem::Function(f) => !impl_fns_consts.contains(&f.name(db).to_string()), hir::AssocItem::TypeAlias(t) => !impl_type.contains(&t.name(db).to_string()), hir::AssocItem::Const(c) => { - c.name(db).map(|n| !impl_const.contains(&n.to_string())).unwrap_or_default() + c.name(db).map(|n| !impl_fns_consts.contains(&n.to_string())).unwrap_or_default() } }) .map(|i| i.clone()) -- cgit v1.2.3