diff options
author | Josh Mcguigan <[email protected]> | 2020-04-11 04:14:53 +0100 |
---|---|---|
committer | Josh Mcguigan <[email protected]> | 2020-04-11 04:14:53 +0100 |
commit | d1338354ca7afae7088f84756ed103ea94ce82f9 (patch) | |
tree | 750a1e7323380d9112ba0a64c9f8a5fff3cf3a13 | |
parent | beb755caa2b1d7265da7d3367af3b49039dfe00e (diff) |
fix match arm false positive
-rw-r--r-- | crates/ra_hir_ty/src/_match.rs | 15 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/expr.rs | 13 |
2 files changed, 16 insertions, 12 deletions
diff --git a/crates/ra_hir_ty/src/_match.rs b/crates/ra_hir_ty/src/_match.rs index 9e9a9d047..342a78b45 100644 --- a/crates/ra_hir_ty/src/_match.rs +++ b/crates/ra_hir_ty/src/_match.rs | |||
@@ -1315,8 +1315,9 @@ mod tests { | |||
1315 | } | 1315 | } |
1316 | "; | 1316 | "; |
1317 | 1317 | ||
1318 | // Match arms with the incorrect type are filtered out. | 1318 | // Match statements with arms that don't match the |
1319 | check_diagnostic(content); | 1319 | // expression pattern do not fire this diagnostic. |
1320 | check_no_diagnostic(content); | ||
1320 | } | 1321 | } |
1321 | 1322 | ||
1322 | #[test] | 1323 | #[test] |
@@ -1330,8 +1331,9 @@ mod tests { | |||
1330 | } | 1331 | } |
1331 | "; | 1332 | "; |
1332 | 1333 | ||
1333 | // Match arms with the incorrect type are filtered out. | 1334 | // Match statements with arms that don't match the |
1334 | check_diagnostic(content); | 1335 | // expression pattern do not fire this diagnostic. |
1336 | check_no_diagnostic(content); | ||
1335 | } | 1337 | } |
1336 | 1338 | ||
1337 | #[test] | 1339 | #[test] |
@@ -1344,8 +1346,9 @@ mod tests { | |||
1344 | } | 1346 | } |
1345 | "; | 1347 | "; |
1346 | 1348 | ||
1347 | // Match arms with the incorrect type are filtered out. | 1349 | // Match statements with arms that don't match the |
1348 | check_diagnostic(content); | 1350 | // expression pattern do not fire this diagnostic. |
1351 | check_no_diagnostic(content); | ||
1349 | } | 1352 | } |
1350 | 1353 | ||
1351 | #[test] | 1354 | #[test] |
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index 827b687de..03ef488b9 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs | |||
@@ -163,12 +163,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
163 | 163 | ||
164 | let mut seen = Matrix::empty(); | 164 | let mut seen = Matrix::empty(); |
165 | for pat in pats { | 165 | for pat in pats { |
166 | // We skip any patterns whose type we cannot resolve. | ||
167 | // | ||
168 | // This could lead to false positives in this diagnostic, so | ||
169 | // it might be better to skip the entire diagnostic if we either | ||
170 | // cannot resolve a match arm or determine that the match arm has | ||
171 | // the wrong type. | ||
172 | if let Some(pat_ty) = infer.type_of_pat.get(pat) { | 166 | if let Some(pat_ty) = infer.type_of_pat.get(pat) { |
173 | // We only include patterns whose type matches the type | 167 | // We only include patterns whose type matches the type |
174 | // of the match expression. If we had a InvalidMatchArmPattern | 168 | // of the match expression. If we had a InvalidMatchArmPattern |
@@ -191,8 +185,15 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
191 | // to the matrix here. | 185 | // to the matrix here. |
192 | let v = PatStack::from_pattern(pat); | 186 | let v = PatStack::from_pattern(pat); |
193 | seen.push(&cx, v); | 187 | seen.push(&cx, v); |
188 | continue; | ||
194 | } | 189 | } |
195 | } | 190 | } |
191 | |||
192 | // If we can't resolve the type of a pattern, or the pattern type doesn't | ||
193 | // fit the match expression, we skip this diagnostic. Skipping the entire | ||
194 | // diagnostic rather than just not including this match arm is preferred | ||
195 | // to avoid the chance of false positives. | ||
196 | return; | ||
196 | } | 197 | } |
197 | 198 | ||
198 | match is_useful(&cx, &seen, &PatStack::from_wild()) { | 199 | match is_useful(&cx, &seen, &PatStack::from_wild()) { |