aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/item_tree
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
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')
-rw-r--r--crates/hir_def/src/item_tree/lower.rs24
1 files changed, 17 insertions, 7 deletions
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs
index 2939c6b1e..b39d7fb7a 100644
--- a/crates/hir_def/src/item_tree/lower.rs
+++ b/crates/hir_def/src/item_tree/lower.rs
@@ -84,8 +84,7 @@ impl Ctx {
84 | ast::Item::Fn(_) 84 | ast::Item::Fn(_)
85 | ast::Item::TypeAlias(_) 85 | ast::Item::TypeAlias(_)
86 | ast::Item::Const(_) 86 | ast::Item::Const(_)
87 | ast::Item::Static(_) 87 | ast::Item::Static(_) => {
88 | ast::Item::MacroCall(_) => {
89 // Skip this if we're already collecting inner items. We'll descend into all nodes 88 // Skip this if we're already collecting inner items. We'll descend into all nodes
90 // already. 89 // already.
91 if !inner { 90 if !inner {
@@ -98,7 +97,11 @@ impl Ctx {
98 ast::Item::Trait(_) | ast::Item::Impl(_) | ast::Item::ExternBlock(_) => {} 97 ast::Item::Trait(_) | ast::Item::Impl(_) | ast::Item::ExternBlock(_) => {}
99 98
100 // These don't have inner items. 99 // These don't have inner items.
101 ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::Use(_) => {} 100 ast::Item::Module(_)
101 | ast::Item::ExternCrate(_)
102 | ast::Item::Use(_)
103 | ast::Item::MacroCall(_)
104 | ast::Item::MacroRules(_) => {}
102 }; 105 };
103 106
104 let attrs = Attrs::new(item, &self.hygiene); 107 let attrs = Attrs::new(item, &self.hygiene);
@@ -118,6 +121,7 @@ impl Ctx {
118 )), 121 )),
119 ast::Item::ExternCrate(ast) => self.lower_extern_crate(ast).map(Into::into), 122 ast::Item::ExternCrate(ast) => self.lower_extern_crate(ast).map(Into::into),
120 ast::Item::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into), 123 ast::Item::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
124 ast::Item::MacroRules(ast) => self.lower_macro_rules(ast).map(Into::into),
121 ast::Item::ExternBlock(ast) => { 125 ast::Item::ExternBlock(ast) => {
122 Some(ModItems(self.lower_extern_block(ast).into_iter().collect::<SmallVec<_>>())) 126 Some(ModItems(self.lower_extern_block(ast).into_iter().collect::<SmallVec<_>>()))
123 } 127 }
@@ -525,9 +529,15 @@ impl Ctx {
525 } 529 }
526 530
527 fn lower_macro_call(&mut self, m: &ast::MacroCall) -> Option<FileItemTreeId<MacroCall>> { 531 fn lower_macro_call(&mut self, m: &ast::MacroCall) -> Option<FileItemTreeId<MacroCall>> {
528 let name = m.name().map(|it| it.as_name());
529 let attrs = Attrs::new(m, &self.hygiene);
530 let path = ModPath::from_src(m.path()?, &self.hygiene)?; 532 let path = ModPath::from_src(m.path()?, &self.hygiene)?;
533 let ast_id = self.source_ast_id_map.ast_id(m);
534 let res = MacroCall { path, ast_id };
535 Some(id(self.data().macro_calls.alloc(res)))
536 }
537
538 fn lower_macro_rules(&mut self, m: &ast::MacroRules) -> Option<FileItemTreeId<MacroRules>> {
539 let name = m.name().map(|it| it.as_name())?;
540 let attrs = Attrs::new(m, &self.hygiene);
531 541
532 let ast_id = self.source_ast_id_map.ast_id(m); 542 let ast_id = self.source_ast_id_map.ast_id(m);
533 543
@@ -547,8 +557,8 @@ impl Ctx {
547 }; 557 };
548 558
549 let is_builtin = attrs.by_key("rustc_builtin_macro").exists(); 559 let is_builtin = attrs.by_key("rustc_builtin_macro").exists();
550 let res = MacroCall { name, path, is_export, is_builtin, is_local_inner, ast_id }; 560 let res = MacroRules { name, is_export, is_builtin, is_local_inner, ast_id };
551 Some(id(self.data().macro_calls.alloc(res))) 561 Some(id(self.data().macro_rules.alloc(res)))
552 } 562 }
553 563
554 fn lower_extern_block(&mut self, block: &ast::ExternBlock) -> Vec<ModItem> { 564 fn lower_extern_block(&mut self, block: &ast::ExternBlock) -> Vec<ModItem> {