Skip to content

Commit d133835

Browse files
committed
fix match arm false positive
1 parent beb755c commit d133835

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

crates/ra_hir_ty/src/_match.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,8 +1315,9 @@ mod tests {
13151315
}
13161316
";
13171317

1318-
// Match arms with the incorrect type are filtered out.
1319-
check_diagnostic(content);
1318+
// Match statements with arms that don't match the
1319+
// expression pattern do not fire this diagnostic.
1320+
check_no_diagnostic(content);
13201321
}
13211322

13221323
#[test]
@@ -1330,8 +1331,9 @@ mod tests {
13301331
}
13311332
";
13321333

1333-
// Match arms with the incorrect type are filtered out.
1334-
check_diagnostic(content);
1334+
// Match statements with arms that don't match the
1335+
// expression pattern do not fire this diagnostic.
1336+
check_no_diagnostic(content);
13351337
}
13361338

13371339
#[test]
@@ -1344,8 +1346,9 @@ mod tests {
13441346
}
13451347
";
13461348

1347-
// Match arms with the incorrect type are filtered out.
1348-
check_diagnostic(content);
1349+
// Match statements with arms that don't match the
1350+
// expression pattern do not fire this diagnostic.
1351+
check_no_diagnostic(content);
13491352
}
13501353

13511354
#[test]

crates/ra_hir_ty/src/expr.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
163163

164164
let mut seen = Matrix::empty();
165165
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.
172166
if let Some(pat_ty) = infer.type_of_pat.get(pat) {
173167
// We only include patterns whose type matches the type
174168
// of the match expression. If we had a InvalidMatchArmPattern
@@ -191,8 +185,15 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
191185
// to the matrix here.
192186
let v = PatStack::from_pattern(pat);
193187
seen.push(&cx, v);
188+
continue;
194189
}
195190
}
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;
196197
}
197198

198199
match is_useful(&cx, &seen, &PatStack::from_wild()) {

0 commit comments

Comments
 (0)