diff options
author | Aleksey Kladov <[email protected]> | 2020-08-18 17:39:43 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-08-18 17:39:43 +0100 |
commit | 8146669542dfc887956901b54a453c9a97fee7e3 (patch) | |
tree | 4408709203c98b63df20204a5630db86914f2e94 /crates/hir_ty/src | |
parent | bbb1c617b9198c230d8331dc0ffc2affb01d2e7a (diff) |
Add type safety to diagnostic codes
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r-- | crates/hir_ty/src/diagnostics.rs | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/crates/hir_ty/src/diagnostics.rs b/crates/hir_ty/src/diagnostics.rs index 38fa24ee0..9ba005fab 100644 --- a/crates/hir_ty/src/diagnostics.rs +++ b/crates/hir_ty/src/diagnostics.rs | |||
@@ -6,7 +6,7 @@ mod unsafe_check; | |||
6 | use std::any::Any; | 6 | use std::any::Any; |
7 | 7 | ||
8 | use hir_def::DefWithBodyId; | 8 | use hir_def::DefWithBodyId; |
9 | use hir_expand::diagnostics::{Diagnostic, DiagnosticSink}; | 9 | use hir_expand::diagnostics::{Diagnostic, DiagnosticCode, DiagnosticSink}; |
10 | use hir_expand::{name::Name, HirFileId, InFile}; | 10 | use hir_expand::{name::Name, HirFileId, InFile}; |
11 | use stdx::format_to; | 11 | use stdx::format_to; |
12 | use syntax::{ast, AstPtr, SyntaxNodePtr}; | 12 | use syntax::{ast, AstPtr, SyntaxNodePtr}; |
@@ -32,8 +32,8 @@ pub struct NoSuchField { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | impl Diagnostic for NoSuchField { | 34 | impl Diagnostic for NoSuchField { |
35 | fn name(&self) -> &'static str { | 35 | fn code(&self) -> DiagnosticCode { |
36 | "no-such-field" | 36 | DiagnosticCode("no-such-field") |
37 | } | 37 | } |
38 | 38 | ||
39 | fn message(&self) -> String { | 39 | fn message(&self) -> String { |
@@ -58,8 +58,8 @@ pub struct MissingFields { | |||
58 | } | 58 | } |
59 | 59 | ||
60 | impl Diagnostic for MissingFields { | 60 | impl Diagnostic for MissingFields { |
61 | fn name(&self) -> &'static str { | 61 | fn code(&self) -> DiagnosticCode { |
62 | "missing-structure-fields" | 62 | DiagnosticCode("missing-structure-fields") |
63 | } | 63 | } |
64 | fn message(&self) -> String { | 64 | fn message(&self) -> String { |
65 | let mut buf = String::from("Missing structure fields:\n"); | 65 | let mut buf = String::from("Missing structure fields:\n"); |
@@ -94,8 +94,8 @@ pub struct MissingPatFields { | |||
94 | } | 94 | } |
95 | 95 | ||
96 | impl Diagnostic for MissingPatFields { | 96 | impl Diagnostic for MissingPatFields { |
97 | fn name(&self) -> &'static str { | 97 | fn code(&self) -> DiagnosticCode { |
98 | "missing-pat-fields" | 98 | DiagnosticCode("missing-pat-fields") |
99 | } | 99 | } |
100 | fn message(&self) -> String { | 100 | fn message(&self) -> String { |
101 | let mut buf = String::from("Missing structure fields:\n"); | 101 | let mut buf = String::from("Missing structure fields:\n"); |
@@ -127,8 +127,8 @@ pub struct MissingMatchArms { | |||
127 | } | 127 | } |
128 | 128 | ||
129 | impl Diagnostic for MissingMatchArms { | 129 | impl Diagnostic for MissingMatchArms { |
130 | fn name(&self) -> &'static str { | 130 | fn code(&self) -> DiagnosticCode { |
131 | "missing-match-arm" | 131 | DiagnosticCode("missing-match-arm") |
132 | } | 132 | } |
133 | fn message(&self) -> String { | 133 | fn message(&self) -> String { |
134 | String::from("Missing match arm") | 134 | String::from("Missing match arm") |
@@ -148,8 +148,8 @@ pub struct MissingOkInTailExpr { | |||
148 | } | 148 | } |
149 | 149 | ||
150 | impl Diagnostic for MissingOkInTailExpr { | 150 | impl Diagnostic for MissingOkInTailExpr { |
151 | fn name(&self) -> &'static str { | 151 | fn code(&self) -> DiagnosticCode { |
152 | "missing-ok-in-tail-expr" | 152 | DiagnosticCode("missing-ok-in-tail-expr") |
153 | } | 153 | } |
154 | fn message(&self) -> String { | 154 | fn message(&self) -> String { |
155 | "wrap return expression in Ok".to_string() | 155 | "wrap return expression in Ok".to_string() |
@@ -169,8 +169,8 @@ pub struct BreakOutsideOfLoop { | |||
169 | } | 169 | } |
170 | 170 | ||
171 | impl Diagnostic for BreakOutsideOfLoop { | 171 | impl Diagnostic for BreakOutsideOfLoop { |
172 | fn name(&self) -> &'static str { | 172 | fn code(&self) -> DiagnosticCode { |
173 | "break-outside-of-loop" | 173 | DiagnosticCode("break-outside-of-loop") |
174 | } | 174 | } |
175 | fn message(&self) -> String { | 175 | fn message(&self) -> String { |
176 | "break outside of loop".to_string() | 176 | "break outside of loop".to_string() |
@@ -190,8 +190,8 @@ pub struct MissingUnsafe { | |||
190 | } | 190 | } |
191 | 191 | ||
192 | impl Diagnostic for MissingUnsafe { | 192 | impl Diagnostic for MissingUnsafe { |
193 | fn name(&self) -> &'static str { | 193 | fn code(&self) -> DiagnosticCode { |
194 | "missing-unsafe" | 194 | DiagnosticCode("missing-unsafe") |
195 | } | 195 | } |
196 | fn message(&self) -> String { | 196 | fn message(&self) -> String { |
197 | format!("This operation is unsafe and requires an unsafe function or block") | 197 | format!("This operation is unsafe and requires an unsafe function or block") |
@@ -213,8 +213,8 @@ pub struct MismatchedArgCount { | |||
213 | } | 213 | } |
214 | 214 | ||
215 | impl Diagnostic for MismatchedArgCount { | 215 | impl Diagnostic for MismatchedArgCount { |
216 | fn name(&self) -> &'static str { | 216 | fn code(&self) -> DiagnosticCode { |
217 | "mismatched-arg-count" | 217 | DiagnosticCode("mismatched-arg-count") |
218 | } | 218 | } |
219 | fn message(&self) -> String { | 219 | fn message(&self) -> String { |
220 | let s = if self.expected == 1 { "" } else { "s" }; | 220 | let s = if self.expected == 1 { "" } else { "s" }; |