aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/body.rs
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-04-04 02:03:18 +0100
committerJonas Schievink <[email protected]>2021-04-04 02:03:18 +0100
commitd8bf9bef800969304440fd2a2a324606a342eaa2 (patch)
tree2c9d20d406f1776648957807189ae543d700782c /crates/hir_def/src/body.rs
parent234ddf34c743924a15cca7480fb3b4db4581308e (diff)
Access a body's block def maps via a method
Diffstat (limited to 'crates/hir_def/src/body.rs')
-rw-r--r--crates/hir_def/src/body.rs12
1 files changed, 11 insertions, 1 deletions
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 {
226 /// The `ExprId` of the actual body expression. 226 /// The `ExprId` of the actual body expression.
227 pub body_expr: ExprId, 227 pub body_expr: ExprId,
228 /// Block expressions in this body that may contain inner items. 228 /// Block expressions in this body that may contain inner items.
229 pub block_scopes: Vec<BlockId>, 229 block_scopes: Vec<BlockId>,
230 _c: Count<Self>, 230 _c: Count<Self>,
231} 231}
232 232
@@ -310,6 +310,16 @@ impl Body {
310 db.body_with_source_map(def).0 310 db.body_with_source_map(def).0
311 } 311 }
312 312
313 /// Returns an iterator over all block expressions in this body that define inner items.
314 pub fn blocks<'a>(
315 &'a self,
316 db: &'a dyn DefDatabase,
317 ) -> impl Iterator<Item = (BlockId, Arc<DefMap>)> + '_ {
318 self.block_scopes
319 .iter()
320 .filter_map(move |block| db.block_def_map(*block).map(|map| (*block, map)))
321 }
322
313 fn new( 323 fn new(
314 db: &dyn DefDatabase, 324 db: &dyn DefDatabase,
315 expander: Expander, 325 expander: Expander,