From d8bf9bef800969304440fd2a2a324606a342eaa2 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sun, 4 Apr 2021 03:03:18 +0200 Subject: Access a body's block def maps via a method --- crates/hir_def/src/body.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'crates/hir_def/src/body.rs') diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index 1080d9c2c..ad3d5afbe 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs @@ -226,7 +226,7 @@ pub struct Body { /// The `ExprId` of the actual body expression. pub body_expr: ExprId, /// Block expressions in this body that may contain inner items. - pub block_scopes: Vec, + block_scopes: Vec, _c: Count, } @@ -310,6 +310,16 @@ impl Body { db.body_with_source_map(def).0 } + /// Returns an iterator over all block expressions in this body that define inner items. + pub fn blocks<'a>( + &'a self, + db: &'a dyn DefDatabase, + ) -> impl Iterator)> + '_ { + self.block_scopes + .iter() + .filter_map(move |block| db.block_def_map(*block).map(|map| (*block, map))) + } + fn new( db: &dyn DefDatabase, expander: Expander, -- cgit v1.2.3