diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-31 13:34:01 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-31 13:34:01 +0100 |
commit | b8d269990c57634e77f4702afc91041bacb4816a (patch) | |
tree | f1d707daa5f4d20abec75299234552b320fa1a42 /crates/hir_def/src/nameres | |
parent | d7cbb49057c4495307d91f5db32465c29c175124 (diff) | |
parent | cb5454db86bae1e97d86b05607b5c36a89fb749b (diff) |
Merge #9060
9060: feat: Diagnose unimplemented built-in macros r=matklad a=jonas-schievink
A number of built-in attribute macros are unsupported, I thought it might be useful to put a diagnostic on their definition in libcore. Not sure.
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src/nameres')
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 48 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/diagnostics.rs | 9 |
2 files changed, 41 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 | } |