diff options
author | Aleksey Kladov <[email protected]> | 2021-06-13 19:44:31 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-06-13 19:44:31 +0100 |
commit | b292e1b9da39813e2739cb450c263e7502c97c8d (patch) | |
tree | 92a09f547c7d7ca41f90ebdc68f0f81ac1805560 /crates/hir/src | |
parent | 3478897f86cc1b3e3f83e9d4e7cedff41721fb04 (diff) |
internal: refactor missing match arms diagnostics
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/diagnostics.rs | 19 | ||||
-rw-r--r-- | crates/hir/src/lib.rs | 13 |
2 files changed, 9 insertions, 23 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index c2d608eb5..5cffef47f 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs | |||
@@ -38,6 +38,7 @@ diagnostics![ | |||
38 | MacroError, | 38 | MacroError, |
39 | MismatchedArgCount, | 39 | MismatchedArgCount, |
40 | MissingFields, | 40 | MissingFields, |
41 | MissingMatchArms, | ||
41 | MissingOkOrSomeInTailExpr, | 42 | MissingOkOrSomeInTailExpr, |
42 | MissingUnsafe, | 43 | MissingUnsafe, |
43 | NoSuchField, | 44 | NoSuchField, |
@@ -149,9 +150,6 @@ pub struct MissingOkOrSomeInTailExpr { | |||
149 | pub required: String, | 150 | pub required: String, |
150 | } | 151 | } |
151 | 152 | ||
152 | // Diagnostic: missing-match-arm | ||
153 | // | ||
154 | // This diagnostic is triggered if `match` block is missing one or more match arms. | ||
155 | #[derive(Debug)] | 153 | #[derive(Debug)] |
156 | pub struct MissingMatchArms { | 154 | pub struct MissingMatchArms { |
157 | pub file: HirFileId, | 155 | pub file: HirFileId, |
@@ -159,21 +157,6 @@ pub struct MissingMatchArms { | |||
159 | pub arms: AstPtr<ast::MatchArmList>, | 157 | pub arms: AstPtr<ast::MatchArmList>, |
160 | } | 158 | } |
161 | 159 | ||
162 | impl Diagnostic for MissingMatchArms { | ||
163 | fn code(&self) -> DiagnosticCode { | ||
164 | DiagnosticCode("missing-match-arm") | ||
165 | } | ||
166 | fn message(&self) -> String { | ||
167 | String::from("Missing match arm") | ||
168 | } | ||
169 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | ||
170 | InFile { file_id: self.file, value: self.match_expr.clone().into() } | ||
171 | } | ||
172 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
173 | self | ||
174 | } | ||
175 | } | ||
176 | |||
177 | #[derive(Debug)] | 160 | #[derive(Debug)] |
178 | pub struct InternalBailedOut { | 161 | pub struct InternalBailedOut { |
179 | pub file: HirFileId, | 162 | pub file: HirFileId, |
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index fc147ade3..2e794ff4a 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -1209,11 +1209,14 @@ impl Function { | |||
1209 | if let (Some(match_expr), Some(arms)) = | 1209 | if let (Some(match_expr), Some(arms)) = |
1210 | (match_expr.expr(), match_expr.match_arm_list()) | 1210 | (match_expr.expr(), match_expr.match_arm_list()) |
1211 | { | 1211 | { |
1212 | sink.push(MissingMatchArms { | 1212 | acc.push( |
1213 | file: source_ptr.file_id, | 1213 | MissingMatchArms { |
1214 | match_expr: AstPtr::new(&match_expr), | 1214 | file: source_ptr.file_id, |
1215 | arms: AstPtr::new(&arms), | 1215 | match_expr: AstPtr::new(&match_expr), |
1216 | }) | 1216 | arms: AstPtr::new(&arms), |
1217 | } | ||
1218 | .into(), | ||
1219 | ) | ||
1217 | } | 1220 | } |
1218 | } | 1221 | } |
1219 | } | 1222 | } |