diff options
Diffstat (limited to 'crates/hir_def/src/nameres/diagnostics.rs')
-rw-r--r-- | crates/hir_def/src/nameres/diagnostics.rs | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/crates/hir_def/src/nameres/diagnostics.rs b/crates/hir_def/src/nameres/diagnostics.rs new file mode 100644 index 000000000..57c36c3c6 --- /dev/null +++ b/crates/hir_def/src/nameres/diagnostics.rs | |||
@@ -0,0 +1,96 @@ | |||
1 | //! Diagnostics emitted during DefMap construction. | ||
2 | |||
3 | use cfg::{CfgExpr, CfgOptions}; | ||
4 | use hir_expand::MacroCallKind; | ||
5 | use la_arena::Idx; | ||
6 | use syntax::ast; | ||
7 | |||
8 | use crate::{ | ||
9 | item_tree::{self, ItemTreeId}, | ||
10 | nameres::LocalModuleId, | ||
11 | path::ModPath, | ||
12 | AstId, | ||
13 | }; | ||
14 | |||
15 | #[derive(Debug, PartialEq, Eq)] | ||
16 | pub enum DefDiagnosticKind { | ||
17 | UnresolvedModule { ast: AstId<ast::Module>, candidate: String }, | ||
18 | |||
19 | UnresolvedExternCrate { ast: AstId<ast::ExternCrate> }, | ||
20 | |||
21 | UnresolvedImport { id: ItemTreeId<item_tree::Import>, index: Idx<ast::UseTree> }, | ||
22 | |||
23 | UnconfiguredCode { ast: AstId<ast::Item>, cfg: CfgExpr, opts: CfgOptions }, | ||
24 | |||
25 | UnresolvedProcMacro { ast: MacroCallKind }, | ||
26 | |||
27 | UnresolvedMacroCall { ast: AstId<ast::MacroCall>, path: ModPath }, | ||
28 | |||
29 | MacroError { ast: MacroCallKind, message: String }, | ||
30 | } | ||
31 | |||
32 | #[derive(Debug, PartialEq, Eq)] | ||
33 | pub struct DefDiagnostic { | ||
34 | pub in_module: LocalModuleId, | ||
35 | pub kind: DefDiagnosticKind, | ||
36 | } | ||
37 | |||
38 | impl DefDiagnostic { | ||
39 | pub(super) fn unresolved_module( | ||
40 | container: LocalModuleId, | ||
41 | declaration: AstId<ast::Module>, | ||
42 | candidate: String, | ||
43 | ) -> Self { | ||
44 | Self { | ||
45 | in_module: container, | ||
46 | kind: DefDiagnosticKind::UnresolvedModule { ast: declaration, candidate }, | ||
47 | } | ||
48 | } | ||
49 | |||
50 | pub(super) fn unresolved_extern_crate( | ||
51 | container: LocalModuleId, | ||
52 | declaration: AstId<ast::ExternCrate>, | ||
53 | ) -> Self { | ||
54 | Self { | ||
55 | in_module: container, | ||
56 | kind: DefDiagnosticKind::UnresolvedExternCrate { ast: declaration }, | ||
57 | } | ||
58 | } | ||
59 | |||
60 | pub(super) fn unresolved_import( | ||
61 | container: LocalModuleId, | ||
62 | id: ItemTreeId<item_tree::Import>, | ||
63 | index: Idx<ast::UseTree>, | ||
64 | ) -> Self { | ||
65 | Self { in_module: container, kind: DefDiagnosticKind::UnresolvedImport { id, index } } | ||
66 | } | ||
67 | |||
68 | pub(super) fn unconfigured_code( | ||
69 | container: LocalModuleId, | ||
70 | ast: AstId<ast::Item>, | ||
71 | cfg: CfgExpr, | ||
72 | opts: CfgOptions, | ||
73 | ) -> Self { | ||
74 | Self { in_module: container, kind: DefDiagnosticKind::UnconfiguredCode { ast, cfg, opts } } | ||
75 | } | ||
76 | |||
77 | pub(super) fn unresolved_proc_macro(container: LocalModuleId, ast: MacroCallKind) -> Self { | ||
78 | Self { in_module: container, kind: DefDiagnosticKind::UnresolvedProcMacro { ast } } | ||
79 | } | ||
80 | |||
81 | pub(super) fn macro_error( | ||
82 | container: LocalModuleId, | ||
83 | ast: MacroCallKind, | ||
84 | message: String, | ||
85 | ) -> Self { | ||
86 | Self { in_module: container, kind: DefDiagnosticKind::MacroError { ast, message } } | ||
87 | } | ||
88 | |||
89 | pub(super) fn unresolved_macro_call( | ||
90 | container: LocalModuleId, | ||
91 | ast: AstId<ast::MacroCall>, | ||
92 | path: ModPath, | ||
93 | ) -> Self { | ||
94 | Self { in_module: container, kind: DefDiagnosticKind::UnresolvedMacroCall { ast, path } } | ||
95 | } | ||
96 | } | ||