From db456749a85e87cdbe3f87b85bf44446d9d5694b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 5 Dec 2018 13:20:11 +0300 Subject: make stuff private --- crates/ra_hir/src/module/mod.rs | 15 ++++----------- crates/ra_hir/src/source_binder.rs | 6 ++++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/crates/ra_hir/src/module/mod.rs b/crates/ra_hir/src/module/mod.rs index 9ab7dbff5..580c737c3 100644 --- a/crates/ra_hir/src/module/mod.rs +++ b/crates/ra_hir/src/module/mod.rs @@ -153,17 +153,10 @@ impl ModuleTree { self.mods.iter().map(|(id, _)| id) } - fn modules_for_source(&self, source: ModuleSource) -> Vec { - self.mods - .iter() - .filter(|(_idx, it)| it.source == source) - .map(|(idx, _)| idx) - .collect() - } - - //TODO: move to source binders? - pub(crate) fn any_module_for_source(&self, source: ModuleSource) -> Option { - self.modules_for_source(source).pop() + pub(crate) fn modules_with_sources<'a>( + &'a self, + ) -> impl Iterator + 'a { + self.mods.iter().map(|(id, m)| (id, m.source)) } } diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index dbf0a4de8..479155805 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -61,8 +61,10 @@ fn module_from_source( ) -> Cancelable> { let source_root_id = db.file_source_root(module_source.file_id()); let module_tree = db.module_tree(source_root_id)?; - - let module_id = ctry!(module_tree.any_module_for_source(module_source)); + let m = module_tree + .modules_with_sources() + .find(|(_id, src)| src == &module_source); + let module_id = ctry!(m).0; Ok(Some(Module::new(db, source_root_id, module_id)?)) } -- cgit v1.2.3