From 2aebde6c0b47a1f2ce3d49af457683258d813cdc Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 28 Jan 2021 18:00:10 +0100 Subject: ItemTree: Treat items in `MacroStmts` as top-level --- crates/hir_def/src/item_tree/lower.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'crates/hir_def/src/item_tree/lower.rs') diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 8a71376b9..acc001add 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -61,6 +61,32 @@ impl Ctx { self.tree } + pub(super) fn lower_macro_stmts(mut self, stmts: ast::MacroStmts) -> ItemTree { + self.tree.top_level = stmts + .statements() + .filter_map(|stmt| match stmt { + ast::Stmt::Item(item) => Some(item), + _ => None, + }) + .flat_map(|item| self.lower_mod_item(&item, false)) + .flat_map(|items| items.0) + .collect(); + + // Non-items need to have their inner items collected. + for stmt in stmts.statements() { + match stmt { + ast::Stmt::ExprStmt(_) | ast::Stmt::LetStmt(_) => { + self.collect_inner_items(stmt.syntax()) + } + _ => {} + } + } + if let Some(expr) = stmts.expr() { + self.collect_inner_items(expr.syntax()); + } + self.tree + } + pub(super) fn lower_inner_items(mut self, within: &SyntaxNode) -> ItemTree { self.collect_inner_items(within); self.tree -- cgit v1.2.3