diff options
Diffstat (limited to 'crates/hir_def')
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 48 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/diagnostics.rs | 9 | ||||
-rw-r--r-- | crates/hir_def/src/test_db.rs | 7 |
3 files changed, 48 insertions, 16 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index d9d6c91a8..50b2b0af4 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -1679,14 +1679,22 @@ impl ModCollector<'_, '_> { | |||
1679 | None => &mac.name, | 1679 | None => &mac.name, |
1680 | }; | 1680 | }; |
1681 | let krate = self.def_collector.def_map.krate; | 1681 | let krate = self.def_collector.def_map.krate; |
1682 | if let Some(macro_id) = find_builtin_macro(name, krate, ast_id) { | 1682 | match find_builtin_macro(name, krate, ast_id) { |
1683 | self.def_collector.define_macro_rules( | 1683 | Some(macro_id) => { |
1684 | self.module_id, | 1684 | self.def_collector.define_macro_rules( |
1685 | mac.name.clone(), | 1685 | self.module_id, |
1686 | macro_id, | 1686 | mac.name.clone(), |
1687 | is_export, | 1687 | macro_id, |
1688 | ); | 1688 | is_export, |
1689 | return; | 1689 | ); |
1690 | return; | ||
1691 | } | ||
1692 | None => { | ||
1693 | self.def_collector | ||
1694 | .def_map | ||
1695 | .diagnostics | ||
1696 | .push(DefDiagnostic::unimplemented_builtin_macro(self.module_id, ast_id)); | ||
1697 | } | ||
1690 | } | 1698 | } |
1691 | } | 1699 | } |
1692 | 1700 | ||
@@ -1715,15 +1723,23 @@ impl ModCollector<'_, '_> { | |||
1715 | let macro_id = find_builtin_macro(&mac.name, krate, ast_id) | 1723 | let macro_id = find_builtin_macro(&mac.name, krate, ast_id) |
1716 | .or_else(|| find_builtin_derive(&mac.name, krate, ast_id)); | 1724 | .or_else(|| find_builtin_derive(&mac.name, krate, ast_id)); |
1717 | 1725 | ||
1718 | if let Some(macro_id) = macro_id { | 1726 | match macro_id { |
1719 | self.def_collector.define_macro_def( | 1727 | Some(macro_id) => { |
1720 | self.module_id, | 1728 | self.def_collector.define_macro_def( |
1721 | mac.name.clone(), | 1729 | self.module_id, |
1722 | macro_id, | 1730 | mac.name.clone(), |
1723 | &self.item_tree[mac.visibility], | 1731 | macro_id, |
1724 | ); | 1732 | &self.item_tree[mac.visibility], |
1733 | ); | ||
1734 | return; | ||
1735 | } | ||
1736 | None => { | ||
1737 | self.def_collector | ||
1738 | .def_map | ||
1739 | .diagnostics | ||
1740 | .push(DefDiagnostic::unimplemented_builtin_macro(self.module_id, ast_id)); | ||
1741 | } | ||
1725 | } | 1742 | } |
1726 | return; | ||
1727 | } | 1743 | } |
1728 | 1744 | ||
1729 | // Case 2: normal `macro` | 1745 | // Case 2: normal `macro` |
diff --git a/crates/hir_def/src/nameres/diagnostics.rs b/crates/hir_def/src/nameres/diagnostics.rs index 57c36c3c6..95061f601 100644 --- a/crates/hir_def/src/nameres/diagnostics.rs +++ b/crates/hir_def/src/nameres/diagnostics.rs | |||
@@ -27,6 +27,8 @@ pub enum DefDiagnosticKind { | |||
27 | UnresolvedMacroCall { ast: AstId<ast::MacroCall>, path: ModPath }, | 27 | UnresolvedMacroCall { ast: AstId<ast::MacroCall>, path: ModPath }, |
28 | 28 | ||
29 | MacroError { ast: MacroCallKind, message: String }, | 29 | MacroError { ast: MacroCallKind, message: String }, |
30 | |||
31 | UnimplementedBuiltinMacro { ast: AstId<ast::Macro> }, | ||
30 | } | 32 | } |
31 | 33 | ||
32 | #[derive(Debug, PartialEq, Eq)] | 34 | #[derive(Debug, PartialEq, Eq)] |
@@ -93,4 +95,11 @@ impl DefDiagnostic { | |||
93 | ) -> Self { | 95 | ) -> Self { |
94 | Self { in_module: container, kind: DefDiagnosticKind::UnresolvedMacroCall { ast, path } } | 96 | Self { in_module: container, kind: DefDiagnosticKind::UnresolvedMacroCall { ast, path } } |
95 | } | 97 | } |
98 | |||
99 | pub(super) fn unimplemented_builtin_macro( | ||
100 | container: LocalModuleId, | ||
101 | ast: AstId<ast::Macro>, | ||
102 | ) -> Self { | ||
103 | Self { in_module: container, kind: DefDiagnosticKind::UnimplementedBuiltinMacro { ast } } | ||
104 | } | ||
96 | } | 105 | } |
diff --git a/crates/hir_def/src/test_db.rs b/crates/hir_def/src/test_db.rs index a9c1e13e2..e840fe5e8 100644 --- a/crates/hir_def/src/test_db.rs +++ b/crates/hir_def/src/test_db.rs | |||
@@ -298,6 +298,13 @@ impl TestDB { | |||
298 | DefDiagnosticKind::MacroError { ast, message } => { | 298 | DefDiagnosticKind::MacroError { ast, message } => { |
299 | (ast.to_node(self.upcast()), message.as_str()) | 299 | (ast.to_node(self.upcast()), message.as_str()) |
300 | } | 300 | } |
301 | DefDiagnosticKind::UnimplementedBuiltinMacro { ast } => { | ||
302 | let node = ast.to_node(self.upcast()); | ||
303 | ( | ||
304 | InFile::new(ast.file_id, node.syntax().clone()), | ||
305 | "UnimplementedBuiltinMacro", | ||
306 | ) | ||
307 | } | ||
301 | }; | 308 | }; |
302 | 309 | ||
303 | let frange = node.as_ref().original_file_range(self); | 310 | let frange = node.as_ref().original_file_range(self); |