diff options
Diffstat (limited to 'crates/hir_def')
-rw-r--r-- | crates/hir_def/src/item_tree.rs | 4 | ||||
-rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 7bb22c4c4..4477bdd36 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs | |||
@@ -115,6 +115,10 @@ impl ItemTree { | |||
115 | // still need to collect inner items. | 115 | // still need to collect inner items. |
116 | ctx.lower_inner_items(stmt.syntax()) | 116 | ctx.lower_inner_items(stmt.syntax()) |
117 | }, | 117 | }, |
118 | ast::Item(item) => { | ||
119 | // Macros can expand to stmt and other item, and we add it as top level item | ||
120 | ctx.lower_single_item(item) | ||
121 | }, | ||
118 | _ => { | 122 | _ => { |
119 | panic!("cannot create item tree from {:?} {}", syntax, syntax); | 123 | panic!("cannot create item tree from {:?} {}", syntax, syntax); |
120 | }, | 124 | }, |
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 7e91b991d..d684b89d0 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs | |||
@@ -87,6 +87,14 @@ impl Ctx { | |||
87 | self.tree | 87 | self.tree |
88 | } | 88 | } |
89 | 89 | ||
90 | pub(super) fn lower_single_item(mut self, item: ast::Item) -> ItemTree { | ||
91 | self.tree.top_level = self | ||
92 | .lower_mod_item(&item, false) | ||
93 | .map(|item| item.0) | ||
94 | .unwrap_or_else(|| Default::default()); | ||
95 | self.tree | ||
96 | } | ||
97 | |||
90 | pub(super) fn lower_inner_items(mut self, within: &SyntaxNode) -> ItemTree { | 98 | pub(super) fn lower_inner_items(mut self, within: &SyntaxNode) -> ItemTree { |
91 | self.collect_inner_items(within); | 99 | self.collect_inner_items(within); |
92 | self.tree | 100 | self.tree |