From 343852d8b24a199b4f2ad4e1149214724b4526db Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 23 Jan 2019 17:57:41 +0300 Subject: simiplify --- crates/ra_hir/src/module_tree.rs | 44 ++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/module_tree.rs b/crates/ra_hir/src/module_tree.rs index c9a15967c..dd3aa6d73 100644 --- a/crates/ra_hir/src/module_tree.rs +++ b/crates/ra_hir/src/module_tree.rs @@ -62,14 +62,26 @@ impl Submodule { file_items: &SourceFileItems, root: &impl ast::ModuleItemOwner, ) -> Vec { - modules(root) - .map(|(name, m)| Submodule { - name, - is_declaration: m.has_semi(), - source: SourceItemId { - file_id, - item_id: Some(file_items.id_of(file_id, m.syntax())), - }, + root.items() + .filter_map(|item| match item.kind() { + ast::ModuleItemKind::Module(m) => Some(m), + _ => None, + }) + .filter_map(|module| { + let name = module.name()?.as_name(); + if !module.has_semi() && module.item_list().is_none() { + tested_by!(name_res_works_for_broken_modules); + return None; + } + let sub = Submodule { + name, + is_declaration: module.has_semi(), + source: SourceItemId { + file_id, + item_id: Some(file_items.id_of(file_id, module.syntax())), + }, + }; + Some(sub) }) .collect() } @@ -209,22 +221,6 @@ impl LinkId { } } -fn modules(root: &impl ast::ModuleItemOwner) -> impl Iterator { - root.items() - .filter_map(|item| match item.kind() { - ast::ModuleItemKind::Module(m) => Some(m), - _ => None, - }) - .filter_map(|module| { - let name = module.name()?.as_name(); - if !module.has_semi() && module.item_list().is_none() { - tested_by!(name_res_works_for_broken_modules); - return None; - } - Some((name, module)) - }) -} - fn create_module_tree<'a>(db: &impl HirDatabase, source_root: SourceRootId) -> ModuleTree { let mut tree = ModuleTree::default(); -- cgit v1.2.3