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