diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-12 15:40:28 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-12 15:40:28 +0100 |
commit | f9e67d692d915b326bd20a4c487039ade377029b (patch) | |
tree | 649f0226ded68ee7883b66ebfbbfcc371d1fba74 /crates/hir/src/diagnostics.rs | |
parent | c1c2c92e47d1db2386f40c446c5a5122912048a7 (diff) | |
parent | 0413d51317a2470c94f82d93e66a3d009fce41a3 (diff) |
Merge #9230
9230: internal: move inference diagnostics to hir r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/hir/src/diagnostics.rs')
-rw-r--r-- | crates/hir/src/diagnostics.rs | 78 |
1 files changed, 76 insertions, 2 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 2cdbd172a..e888fc23b 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs | |||
@@ -14,8 +14,7 @@ use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange}; | |||
14 | pub use hir_ty::{ | 14 | pub use hir_ty::{ |
15 | diagnostics::{ | 15 | diagnostics::{ |
16 | IncorrectCase, MismatchedArgCount, MissingFields, MissingMatchArms, | 16 | IncorrectCase, MismatchedArgCount, MissingFields, MissingMatchArms, |
17 | MissingOkOrSomeInTailExpr, NoSuchField, RemoveThisSemicolon, | 17 | MissingOkOrSomeInTailExpr, RemoveThisSemicolon, ReplaceFilterMapNextWithFindMap, |
18 | ReplaceFilterMapNextWithFindMap, | ||
19 | }, | 18 | }, |
20 | diagnostics_sink::{Diagnostic, DiagnosticCode, DiagnosticSink, DiagnosticSinkBuilder}, | 19 | diagnostics_sink::{Diagnostic, DiagnosticCode, DiagnosticSink, DiagnosticSinkBuilder}, |
21 | }; | 20 | }; |
@@ -251,3 +250,78 @@ impl Diagnostic for UnimplementedBuiltinMacro { | |||
251 | self | 250 | self |
252 | } | 251 | } |
253 | } | 252 | } |
253 | |||
254 | // Diagnostic: no-such-field | ||
255 | // | ||
256 | // This diagnostic is triggered if created structure does not have field provided in record. | ||
257 | #[derive(Debug)] | ||
258 | pub struct NoSuchField { | ||
259 | pub file: HirFileId, | ||
260 | pub field: AstPtr<ast::RecordExprField>, | ||
261 | } | ||
262 | |||
263 | impl Diagnostic for NoSuchField { | ||
264 | fn code(&self) -> DiagnosticCode { | ||
265 | DiagnosticCode("no-such-field") | ||
266 | } | ||
267 | |||
268 | fn message(&self) -> String { | ||
269 | "no such field".to_string() | ||
270 | } | ||
271 | |||
272 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | ||
273 | InFile::new(self.file, self.field.clone().into()) | ||
274 | } | ||
275 | |||
276 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
277 | self | ||
278 | } | ||
279 | } | ||
280 | |||
281 | // Diagnostic: break-outside-of-loop | ||
282 | // | ||
283 | // This diagnostic is triggered if the `break` keyword is used outside of a loop. | ||
284 | #[derive(Debug)] | ||
285 | pub struct BreakOutsideOfLoop { | ||
286 | pub file: HirFileId, | ||
287 | pub expr: AstPtr<ast::Expr>, | ||
288 | } | ||
289 | |||
290 | impl Diagnostic for BreakOutsideOfLoop { | ||
291 | fn code(&self) -> DiagnosticCode { | ||
292 | DiagnosticCode("break-outside-of-loop") | ||
293 | } | ||
294 | fn message(&self) -> String { | ||
295 | "break outside of loop".to_string() | ||
296 | } | ||
297 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | ||
298 | InFile { file_id: self.file, value: self.expr.clone().into() } | ||
299 | } | ||
300 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
301 | self | ||
302 | } | ||
303 | } | ||
304 | |||
305 | // Diagnostic: missing-unsafe | ||
306 | // | ||
307 | // This diagnostic is triggered if an operation marked as `unsafe` is used outside of an `unsafe` function or block. | ||
308 | #[derive(Debug)] | ||
309 | pub struct MissingUnsafe { | ||
310 | pub file: HirFileId, | ||
311 | pub expr: AstPtr<ast::Expr>, | ||
312 | } | ||
313 | |||
314 | impl Diagnostic for MissingUnsafe { | ||
315 | fn code(&self) -> DiagnosticCode { | ||
316 | DiagnosticCode("missing-unsafe") | ||
317 | } | ||
318 | fn message(&self) -> String { | ||
319 | format!("This operation is unsafe and requires an unsafe function or block") | ||
320 | } | ||
321 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | ||
322 | InFile { file_id: self.file, value: self.expr.clone().into() } | ||
323 | } | ||
324 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
325 | self | ||
326 | } | ||
327 | } | ||