aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/item_tree.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/item_tree.rs')
-rw-r--r--crates/hir_def/src/item_tree.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs
index b08167281..1c9babf37 100644
--- a/crates/hir_def/src/item_tree.rs
+++ b/crates/hir_def/src/item_tree.rs
@@ -94,6 +94,9 @@ impl ItemTree {
94 ast::MacroItems(items) => { 94 ast::MacroItems(items) => {
95 ctx.lower_module_items(&items) 95 ctx.lower_module_items(&items)
96 }, 96 },
97 ast::MacroStmts(stmts) => {
98 ctx.lower_inner_items(stmts.syntax())
99 },
97 // Macros can expand to expressions. We return an empty item tree in this case, but 100 // Macros can expand to expressions. We return an empty item tree in this case, but
98 // still need to collect inner items. 101 // still need to collect inner items.
99 ast::Expr(e) => { 102 ast::Expr(e) => {
@@ -139,6 +142,7 @@ impl ItemTree {
139 type_aliases, 142 type_aliases,
140 mods, 143 mods,
141 macro_calls, 144 macro_calls,
145 macro_rules,
142 exprs, 146 exprs,
143 vis, 147 vis,
144 generics, 148 generics,
@@ -159,6 +163,7 @@ impl ItemTree {
159 type_aliases.shrink_to_fit(); 163 type_aliases.shrink_to_fit();
160 mods.shrink_to_fit(); 164 mods.shrink_to_fit();
161 macro_calls.shrink_to_fit(); 165 macro_calls.shrink_to_fit();
166 macro_rules.shrink_to_fit();
162 exprs.shrink_to_fit(); 167 exprs.shrink_to_fit();
163 168
164 vis.arena.shrink_to_fit(); 169 vis.arena.shrink_to_fit();
@@ -277,6 +282,7 @@ struct ItemTreeData {
277 type_aliases: Arena<TypeAlias>, 282 type_aliases: Arena<TypeAlias>,
278 mods: Arena<Mod>, 283 mods: Arena<Mod>,
279 macro_calls: Arena<MacroCall>, 284 macro_calls: Arena<MacroCall>,
285 macro_rules: Arena<MacroRules>,
280 exprs: Arena<Expr>, 286 exprs: Arena<Expr>,
281 287
282 vis: ItemVisibilities, 288 vis: ItemVisibilities,
@@ -424,6 +430,7 @@ mod_items! {
424 TypeAlias in type_aliases -> ast::TypeAlias, 430 TypeAlias in type_aliases -> ast::TypeAlias,
425 Mod in mods -> ast::Module, 431 Mod in mods -> ast::Module,
426 MacroCall in macro_calls -> ast::MacroCall, 432 MacroCall in macro_calls -> ast::MacroCall,
433 MacroRules in macro_rules -> ast::MacroRules,
427} 434}
428 435
429macro_rules! impl_index { 436macro_rules! impl_index {
@@ -626,17 +633,22 @@ pub enum ModKind {
626 633
627#[derive(Debug, Clone, Eq, PartialEq)] 634#[derive(Debug, Clone, Eq, PartialEq)]
628pub struct MacroCall { 635pub struct MacroCall {
629 /// For `macro_rules!` declarations, this is the name of the declared macro.
630 pub name: Option<Name>,
631 /// Path to the called macro. 636 /// Path to the called macro.
632 pub path: ModPath, 637 pub path: ModPath,
638 pub ast_id: FileAstId<ast::MacroCall>,
639}
640
641#[derive(Debug, Clone, Eq, PartialEq)]
642pub struct MacroRules {
643 /// For `macro_rules!` declarations, this is the name of the declared macro.
644 pub name: Name,
633 /// Has `#[macro_export]`. 645 /// Has `#[macro_export]`.
634 pub is_export: bool, 646 pub is_export: bool,
635 /// Has `#[macro_export(local_inner_macros)]`. 647 /// Has `#[macro_export(local_inner_macros)]`.
636 pub is_local_inner: bool, 648 pub is_local_inner: bool,
637 /// Has `#[rustc_builtin_macro]`. 649 /// Has `#[rustc_builtin_macro]`.
638 pub is_builtin: bool, 650 pub is_builtin: bool,
639 pub ast_id: FileAstId<ast::MacroCall>, 651 pub ast_id: FileAstId<ast::MacroRules>,
640} 652}
641 653
642// NB: There's no `FileAstId` for `Expr`. The only case where this would be useful is for array 654// NB: There's no `FileAstId` for `Expr`. The only case where this would be useful is for array
@@ -667,7 +679,8 @@ impl ModItem {
667 | ModItem::Static(_) 679 | ModItem::Static(_)
668 | ModItem::Trait(_) 680 | ModItem::Trait(_)
669 | ModItem::Impl(_) 681 | ModItem::Impl(_)
670 | ModItem::Mod(_) => None, 682 | ModItem::Mod(_)
683 | ModItem::MacroRules(_) => None,
671 ModItem::MacroCall(call) => Some(AssocItem::MacroCall(*call)), 684 ModItem::MacroCall(call) => Some(AssocItem::MacroCall(*call)),
672 ModItem::Const(konst) => Some(AssocItem::Const(*konst)), 685 ModItem::Const(konst) => Some(AssocItem::Const(*konst)),
673 ModItem::TypeAlias(alias) => Some(AssocItem::TypeAlias(*alias)), 686 ModItem::TypeAlias(alias) => Some(AssocItem::TypeAlias(*alias)),
@@ -694,6 +707,7 @@ impl ModItem {
694 ModItem::TypeAlias(it) => tree[it.index].ast_id().upcast(), 707 ModItem::TypeAlias(it) => tree[it.index].ast_id().upcast(),
695 ModItem::Mod(it) => tree[it.index].ast_id().upcast(), 708 ModItem::Mod(it) => tree[it.index].ast_id().upcast(),
696 ModItem::MacroCall(it) => tree[it.index].ast_id().upcast(), 709 ModItem::MacroCall(it) => tree[it.index].ast_id().upcast(),
710 ModItem::MacroRules(it) => tree[it.index].ast_id().upcast(),
697 } 711 }
698 } 712 }
699} 713}