From ae9530addc4c5e9bbfd5c0287d3c3adb2de95e40 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 28 Dec 2018 14:34:00 +0100 Subject: Add HIR for impl blocks Since we need to be able to go from def to containing impl block, as well as the other direction, and to find all impls for a certain type, a design similar to the one for modules, where we collect all impls for the whole crate and keep them in an arena, seemed fitting. The ImplBlock type, which provides the public interface, then consists only of an Arc to the arena containing all impls, and the index into it. --- crates/ra_hir/src/module.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'crates/ra_hir/src/module.rs') diff --git a/crates/ra_hir/src/module.rs b/crates/ra_hir/src/module.rs index c70dc54dd..b9821115c 100644 --- a/crates/ra_hir/src/module.rs +++ b/crates/ra_hir/src/module.rs @@ -71,6 +71,21 @@ impl Module { }) } + /// Returns an iterator of all children of this module. + pub fn children<'a>(&'a self) -> impl Iterator + 'a { + self.module_id + .children(&self.tree) + .map(move |(name, module_id)| { + ( + name, + Module { + module_id, + ..self.clone() + }, + ) + }) + } + /// Returns the crate this module is part of. pub fn krate(&self, db: &impl HirDatabase) -> Option { let root_id = self.module_id.crate_root(&self.tree); -- cgit v1.2.3