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