aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/expr.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-04-12 09:30:24 +0100
committerGitHub <[email protected]>2020-04-12 09:30:24 +0100
commit268b7987290143550461090c2c0e23371813dbec (patch)
tree5dcdab30670131d405d34d0c20a8785bbf1ee181 /crates/ra_hir_ty/src/expr.rs
parenta8e032820f14cad3630299a1ae16c62dcf59f358 (diff)
parentbb2e5308b77e5d115df17411aaa2dd26be171b0a (diff)
Merge #3938
3938: fix missing match arm false positive r=flodiebold a=JoshMcguigan This fixes #3932 by skipping the missing match arm diagnostic in the case any of the match arms don't type check properly against the match expression. I think this is the appropriate behavior for this diagnostic, since `is_useful` relies on all match arms being well formed, and the case of a malformed match arm should probably be handled by a different diagnostic. Co-authored-by: Josh Mcguigan <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/expr.rs')
-rw-r--r--crates/ra_hir_ty/src/expr.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs
index 69b527f74..21abbcf1e 100644
--- a/crates/ra_hir_ty/src/expr.rs
+++ b/crates/ra_hir_ty/src/expr.rs
@@ -161,12 +161,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
161 161
162 let mut seen = Matrix::empty(); 162 let mut seen = Matrix::empty();
163 for pat in pats { 163 for pat in pats {
164 // We skip any patterns whose type we cannot resolve.
165 //
166 // This could lead to false positives in this diagnostic, so
167 // it might be better to skip the entire diagnostic if we either
168 // cannot resolve a match arm or determine that the match arm has
169 // the wrong type.
170 if let Some(pat_ty) = infer.type_of_pat.get(pat) { 164 if let Some(pat_ty) = infer.type_of_pat.get(pat) {
171 // We only include patterns whose type matches the type 165 // We only include patterns whose type matches the type
172 // of the match expression. If we had a InvalidMatchArmPattern 166 // of the match expression. If we had a InvalidMatchArmPattern
@@ -189,8 +183,15 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
189 // to the matrix here. 183 // to the matrix here.
190 let v = PatStack::from_pattern(pat); 184 let v = PatStack::from_pattern(pat);
191 seen.push(&cx, v); 185 seen.push(&cx, v);
186 continue;
192 } 187 }
193 } 188 }
189
190 // If we can't resolve the type of a pattern, or the pattern type doesn't
191 // fit the match expression, we skip this diagnostic. Skipping the entire
192 // diagnostic rather than just not including this match arm is preferred
193 // to avoid the chance of false positives.
194 return;
194 } 195 }
195 196
196 match is_useful(&cx, &seen, &PatStack::from_wild()) { 197 match is_useful(&cx, &seen, &PatStack::from_wild()) {