mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
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 <joshmcg88@gmail.com>
This commit is contained in:
commit
268b798729
2 changed files with 253 additions and 12 deletions
|
@ -161,12 +161,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
|||
|
||||
let mut seen = Matrix::empty();
|
||||
for pat in pats {
|
||||
// We skip any patterns whose type we cannot resolve.
|
||||
//
|
||||
// This could lead to false positives in this diagnostic, so
|
||||
// it might be better to skip the entire diagnostic if we either
|
||||
// cannot resolve a match arm or determine that the match arm has
|
||||
// the wrong type.
|
||||
if let Some(pat_ty) = infer.type_of_pat.get(pat) {
|
||||
// We only include patterns whose type matches the type
|
||||
// of the match expression. If we had a InvalidMatchArmPattern
|
||||
|
@ -189,8 +183,15 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
|||
// to the matrix here.
|
||||
let v = PatStack::from_pattern(pat);
|
||||
seen.push(&cx, v);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// If we can't resolve the type of a pattern, or the pattern type doesn't
|
||||
// fit the match expression, we skip this diagnostic. Skipping the entire
|
||||
// diagnostic rather than just not including this match arm is preferred
|
||||
// to avoid the chance of false positives.
|
||||
return;
|
||||
}
|
||||
|
||||
match is_useful(&cx, &seen, &PatStack::from_wild()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue