From 52fe50a97b702f3e72600b19936f5f355d897d1e Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 19 Jan 2021 19:49:19 +0100 Subject: Record `FileAstId`s for block expressiosn Every block expression may contain inner items, so we need to be able to refer to any block expression and use it as a salsa key. --- crates/hir_expand/src/ast_id_map.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'crates/hir_expand/src/ast_id_map.rs') 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::{ }; use la_arena::{Arena, Idx}; -use syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr}; +use syntax::{ast, match_ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr}; /// `AstId` points to an AST node in a specific file. pub struct FileAstId { @@ -72,12 +72,20 @@ impl AstIdMap { // get lower ids then children. That is, adding a new child does not // change parent's id. This means that, say, adding a new function to a // trait does not change ids of top-level items, which helps caching. - bdfs(node, |it| match ast::Item::cast(it) { - Some(module_item) => { - res.alloc(module_item.syntax()); - true + bdfs(node, |it| { + match_ast! { + match it { + ast::Item(module_item) => { + res.alloc(module_item.syntax()); + true + }, + ast::BlockExpr(block) => { + res.alloc(block.syntax()); + true + }, + _ => false, + } } - None => false, }); res } -- cgit v1.2.3