aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/item_tree.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-12-15 14:45:09 +0000
committerGitHub <[email protected]>2020-12-15 14:45:09 +0000
commitbd4c352831662762ee7a66da77ec9adf623b0a0a (patch)
tree725dfad20b95344ad363b35860cf7e57067bb5e5 /crates/hir_def/src/item_tree.rs
parent39aae835fd70d06092c1be1add6eef3984439529 (diff)
parent479babf8740a4d3cf6fc03a5f4a2fca00d387501 (diff)
Merge #6893
6893: Move to upstream `macro_rules!` model r=matklad a=jonas-schievink This changes `macro_rules!` from being treated as a macro invocation to being a first-class item. It also disallows using an additional ident argument for regular macros, so `m! ident(...);` now fails to parse. This matches upstream Rust, and makes the code somewhat simpler by removing repeated "is this a `macro_rules!` call" checks. It will also simplify allowing visibilities on macros, which is currently being proposed in https://github.com/rust-lang/rust/pull/78166. Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src/item_tree.rs')
-rw-r--r--crates/hir_def/src/item_tree.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs
index 864fad170..1c9babf37 100644
--- a/crates/hir_def/src/item_tree.rs
+++ b/crates/hir_def/src/item_tree.rs
@@ -142,6 +142,7 @@ impl ItemTree {
142 type_aliases, 142 type_aliases,
143 mods, 143 mods,
144 macro_calls, 144 macro_calls,
145 macro_rules,
145 exprs, 146 exprs,
146 vis, 147 vis,
147 generics, 148 generics,
@@ -162,6 +163,7 @@ impl ItemTree {
162 type_aliases.shrink_to_fit(); 163 type_aliases.shrink_to_fit();
163 mods.shrink_to_fit(); 164 mods.shrink_to_fit();
164 macro_calls.shrink_to_fit(); 165 macro_calls.shrink_to_fit();
166 macro_rules.shrink_to_fit();
165 exprs.shrink_to_fit(); 167 exprs.shrink_to_fit();
166 168
167 vis.arena.shrink_to_fit(); 169 vis.arena.shrink_to_fit();
@@ -280,6 +282,7 @@ struct ItemTreeData {
280 type_aliases: Arena<TypeAlias>, 282 type_aliases: Arena<TypeAlias>,
281 mods: Arena<Mod>, 283 mods: Arena<Mod>,
282 macro_calls: Arena<MacroCall>, 284 macro_calls: Arena<MacroCall>,
285 macro_rules: Arena<MacroRules>,
283 exprs: Arena<Expr>, 286 exprs: Arena<Expr>,
284 287
285 vis: ItemVisibilities, 288 vis: ItemVisibilities,
@@ -427,6 +430,7 @@ mod_items! {
427 TypeAlias in type_aliases -> ast::TypeAlias, 430 TypeAlias in type_aliases -> ast::TypeAlias,
428 Mod in mods -> ast::Module, 431 Mod in mods -> ast::Module,
429 MacroCall in macro_calls -> ast::MacroCall, 432 MacroCall in macro_calls -> ast::MacroCall,
433 MacroRules in macro_rules -> ast::MacroRules,
430} 434}
431 435
432macro_rules! impl_index { 436macro_rules! impl_index {
@@ -629,17 +633,22 @@ pub enum ModKind {
629 633
630#[derive(Debug, Clone, Eq, PartialEq)] 634#[derive(Debug, Clone, Eq, PartialEq)]
631pub struct MacroCall { 635pub struct MacroCall {
632 /// For `macro_rules!` declarations, this is the name of the declared macro.
633 pub name: Option<Name>,
634 /// Path to the called macro. 636 /// Path to the called macro.
635 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,
636 /// Has `#[macro_export]`. 645 /// Has `#[macro_export]`.
637 pub is_export: bool, 646 pub is_export: bool,
638 /// Has `#[macro_export(local_inner_macros)]`. 647 /// Has `#[macro_export(local_inner_macros)]`.
639 pub is_local_inner: bool, 648 pub is_local_inner: bool,
640 /// Has `#[rustc_builtin_macro]`. 649 /// Has `#[rustc_builtin_macro]`.
641 pub is_builtin: bool, 650 pub is_builtin: bool,
642 pub ast_id: FileAstId<ast::MacroCall>, 651 pub ast_id: FileAstId<ast::MacroRules>,
643} 652}
644 653
645// 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
@@ -670,7 +679,8 @@ impl ModItem {
670 | ModItem::Static(_) 679 | ModItem::Static(_)
671 | ModItem::Trait(_) 680 | ModItem::Trait(_)
672 | ModItem::Impl(_) 681 | ModItem::Impl(_)
673 | ModItem::Mod(_) => None, 682 | ModItem::Mod(_)
683 | ModItem::MacroRules(_) => None,
674 ModItem::MacroCall(call) => Some(AssocItem::MacroCall(*call)), 684 ModItem::MacroCall(call) => Some(AssocItem::MacroCall(*call)),
675 ModItem::Const(konst) => Some(AssocItem::Const(*konst)), 685 ModItem::Const(konst) => Some(AssocItem::Const(*konst)),
676 ModItem::TypeAlias(alias) => Some(AssocItem::TypeAlias(*alias)), 686 ModItem::TypeAlias(alias) => Some(AssocItem::TypeAlias(*alias)),
@@ -697,6 +707,7 @@ impl ModItem {
697 ModItem::TypeAlias(it) => tree[it.index].ast_id().upcast(), 707 ModItem::TypeAlias(it) => tree[it.index].ast_id().upcast(),
698 ModItem::Mod(it) => tree[it.index].ast_id().upcast(), 708 ModItem::Mod(it) => tree[it.index].ast_id().upcast(),
699 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(),
700 } 711 }
701 } 712 }
702} 713}