From e214c3a6bd7f74b42d38663b959fc4f0d113c90c Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 1 Mar 2021 13:55:47 +0200 Subject: Simplify --- crates/ide_db/src/helpers/import_assets.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'crates/ide_db/src/helpers') diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs index 2909ecd45..4e352d546 100644 --- a/crates/ide_db/src/helpers/import_assets.rs +++ b/crates/ide_db/src/helpers/import_assets.rs @@ -130,7 +130,6 @@ impl<'a> ImportAssets<'a> { #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct LocatedImport { - // TODO kb extract both into a separate struct + add another field: `assoc_item_name: Optional` import_path: ModPath, item_to_import: ItemInNs, data_to_display: Option<(ModPath, ItemInNs)>, @@ -146,7 +145,7 @@ impl LocatedImport { } pub fn display_path(&self) -> &ModPath { - self.data_to_display.as_ref().map(|(mod_pathh, _)| mod_pathh).unwrap_or(&self.import_path) + self.data_to_display.as_ref().map(|(mod_path, _)| mod_path).unwrap_or(&self.import_path) } pub fn import_path(&self) -> &ModPath { @@ -227,14 +226,7 @@ impl<'a> ImportAssets<'a> { self.applicable_defs(sema.db, prefixed, defs_for_candidate_name) .into_iter() .filter(|import| import.import_path().len() > 1) - .filter(|import| { - let proposed_def = match import.item_to_import() { - ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()), - ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()), - ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()), - }; - !scope_definitions.contains(&proposed_def) - }) + .filter(|import| !scope_definitions.contains(&ScopeDef::from(import.item_to_import()))) .collect() } @@ -314,8 +306,8 @@ fn import_for_item( unresolved_qualifier: &str, original_item: ItemInNs, ) -> Option { - let (item_candidate, trait_to_import) = match original_item { - ItemInNs::Types(module_def_id) | ItemInNs::Values(module_def_id) => { + let (item_candidate, trait_to_import) = match original_item.as_module_def_id() { + Some(module_def_id) => { match ModuleDef::from(module_def_id).as_assoc_item(db).map(|assoc| assoc.container(db)) { Some(AssocItemContainer::Trait(trait_)) => { @@ -328,7 +320,7 @@ fn import_for_item( None => (original_item, None), } } - ItemInNs::Macros(_) => (original_item, None), + None => (original_item, None), }; let import_path_candidate = mod_path(item_candidate)?; -- cgit v1.2.3