diff options
author | Jonas Schievink <[email protected]> | 2020-12-15 14:37:37 +0000 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-12-15 14:37:37 +0000 |
commit | c1cb5953820f26d4d0a614650bc8c50cbc5a3ce6 (patch) | |
tree | 01ba67d97ce6f261154df59b268fe924af9add2a /crates/hir_def/src/item_tree | |
parent | 39aae835fd70d06092c1be1add6eef3984439529 (diff) |
Move to upstream `macro_rules!` model
Diffstat (limited to 'crates/hir_def/src/item_tree')
-rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 24 |
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> { |