diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-20 16:09:22 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-20 16:09:22 +0000 |
commit | e62533c3ec74358d3488e8e4b7967c78459b238f (patch) | |
tree | cd1fe4ad8f6a19b44678e1389c0c7553a6d11036 /crates/hir_expand | |
parent | 9d10aa09726f38d184d499c0a04f8ba4bc1c2bba (diff) | |
parent | c5ed2284b5733dcaf8b57b1771c441afc39fa5e7 (diff) |
Merge #7359
7359: ItemTree: store a mapping from blocks to inner items r=jonas-schievink a=jonas-schievink
To do name resolution within block expressions, we need to know which inner items are located inside each block expression. This adds such a mapping to `ItemTree`, replacing the previous one, which was seemingly unused other than to access all the inner items.
This also assigns `AstId`s to block expressions, which is needed to store the mapping in salsa.
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_expand')
-rw-r--r-- | crates/hir_expand/src/ast_id_map.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/crates/hir_expand/src/ast_id_map.rs b/crates/hir_expand/src/ast_id_map.rs index 2401b0cc5..0991fffd8 100644 --- a/crates/hir_expand/src/ast_id_map.rs +++ b/crates/hir_expand/src/ast_id_map.rs | |||
@@ -13,7 +13,7 @@ use std::{ | |||
13 | }; | 13 | }; |
14 | 14 | ||
15 | use la_arena::{Arena, Idx}; | 15 | use la_arena::{Arena, Idx}; |
16 | use syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr}; | 16 | use syntax::{ast, match_ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr}; |
17 | 17 | ||
18 | /// `AstId` points to an AST node in a specific file. | 18 | /// `AstId` points to an AST node in a specific file. |
19 | pub struct FileAstId<N: AstNode> { | 19 | pub struct FileAstId<N: AstNode> { |
@@ -72,12 +72,20 @@ impl AstIdMap { | |||
72 | // get lower ids then children. That is, adding a new child does not | 72 | // get lower ids then children. That is, adding a new child does not |
73 | // change parent's id. This means that, say, adding a new function to a | 73 | // change parent's id. This means that, say, adding a new function to a |
74 | // trait does not change ids of top-level items, which helps caching. | 74 | // trait does not change ids of top-level items, which helps caching. |
75 | bdfs(node, |it| match ast::Item::cast(it) { | 75 | bdfs(node, |it| { |
76 | Some(module_item) => { | 76 | match_ast! { |
77 | res.alloc(module_item.syntax()); | 77 | match it { |
78 | true | 78 | ast::Item(module_item) => { |
79 | res.alloc(module_item.syntax()); | ||
80 | true | ||
81 | }, | ||
82 | ast::BlockExpr(block) => { | ||
83 | res.alloc(block.syntax()); | ||
84 | true | ||
85 | }, | ||
86 | _ => false, | ||
87 | } | ||
79 | } | 88 | } |
80 | None => false, | ||
81 | }); | 89 | }); |
82 | res | 90 | res |
83 | } | 91 | } |