diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-07 13:53:47 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-07 13:53:47 +0100 |
commit | 97b963b44b9da1fca4229da4c8744fa88c25780b (patch) | |
tree | f25e0db350072cf8d084ce81adcaeeeaac3f4c42 /crates/ra_hir_ty/src/diagnostics.rs | |
parent | b7e5d94bda362ffc21174a79aa0be113c3288e1e (diff) | |
parent | 9fc1f51b7ade2cda7d410450ab1347311eb074af (diff) |
Merge #3706
3706: missing match arms diagnostic r=flodiebold a=JoshMcguigan
Following up on https://github.com/rust-analyzer/rust-analyzer/pull/3689#issuecomment-602718222, this PR creates a missing match arms diagnostic.
At the moment this is a very early draft, but I wanted to open it just to get some initial feedback.
Initial questions:
* Have I roughly created the correct boilerplate?
* Inside the new `validate_match` function:
* Am I correct in thinking I want to do validation by comparing the match arms against `match_expr`? And when analyzing `match_expr` I should be looking at it as a `hir_def::expr::Expr`?
* I mostly copied the chained if-let statements from the struct validation. Shouldn't there be a non-failable way to get an AstPtr from the hir data structures?
Thanks for all the guidance.
Co-authored-by: Josh Mcguigan <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/diagnostics.rs')
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 0f8522021..8cbce1168 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs | |||
@@ -6,7 +6,7 @@ use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; | |||
6 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; | 6 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; |
7 | use stdx::format_to; | 7 | use stdx::format_to; |
8 | 8 | ||
9 | pub use hir_def::diagnostics::UnresolvedModule; | 9 | pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm}; |
10 | pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; | 10 | pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; |
11 | 11 | ||
12 | #[derive(Debug)] | 12 | #[derive(Debug)] |
@@ -63,6 +63,25 @@ impl AstDiagnostic for MissingFields { | |||
63 | } | 63 | } |
64 | 64 | ||
65 | #[derive(Debug)] | 65 | #[derive(Debug)] |
66 | pub struct MissingMatchArms { | ||
67 | pub file: HirFileId, | ||
68 | pub match_expr: AstPtr<ast::Expr>, | ||
69 | pub arms: AstPtr<ast::MatchArmList>, | ||
70 | } | ||
71 | |||
72 | impl Diagnostic for MissingMatchArms { | ||
73 | fn message(&self) -> String { | ||
74 | String::from("Missing match arm") | ||
75 | } | ||
76 | fn source(&self) -> InFile<SyntaxNodePtr> { | ||
77 | InFile { file_id: self.file, value: self.match_expr.into() } | ||
78 | } | ||
79 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
80 | self | ||
81 | } | ||
82 | } | ||
83 | |||
84 | #[derive(Debug)] | ||
66 | pub struct MissingOkInTailExpr { | 85 | pub struct MissingOkInTailExpr { |
67 | pub file: HirFileId, | 86 | pub file: HirFileId, |
68 | pub expr: AstPtr<ast::Expr>, | 87 | pub expr: AstPtr<ast::Expr>, |