fix match arm false positive
This commit is contained in:
@@ -1315,8 +1315,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
";
|
";
|
||||||
|
|
||||||
// Match arms with the incorrect type are filtered out.
|
// Match statements with arms that don't match the
|
||||||
check_diagnostic(content);
|
// expression pattern do not fire this diagnostic.
|
||||||
|
check_no_diagnostic(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -1330,8 +1331,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
";
|
";
|
||||||
|
|
||||||
// Match arms with the incorrect type are filtered out.
|
// Match statements with arms that don't match the
|
||||||
check_diagnostic(content);
|
// expression pattern do not fire this diagnostic.
|
||||||
|
check_no_diagnostic(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -1344,8 +1346,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
";
|
";
|
||||||
|
|
||||||
// Match arms with the incorrect type are filtered out.
|
// Match statements with arms that don't match the
|
||||||
check_diagnostic(content);
|
// expression pattern do not fire this diagnostic.
|
||||||
|
check_no_diagnostic(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -163,12 +163,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
|||||||
|
|
||||||
let mut seen = Matrix::empty();
|
let mut seen = Matrix::empty();
|
||||||
for pat in pats {
|
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) {
|
if let Some(pat_ty) = infer.type_of_pat.get(pat) {
|
||||||
// We only include patterns whose type matches the type
|
// We only include patterns whose type matches the type
|
||||||
// of the match expression. If we had a InvalidMatchArmPattern
|
// of the match expression. If we had a InvalidMatchArmPattern
|
||||||
@@ -191,8 +185,15 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
|||||||
// to the matrix here.
|
// to the matrix here.
|
||||||
let v = PatStack::from_pattern(pat);
|
let v = PatStack::from_pattern(pat);
|
||||||
seen.push(&cx, v);
|
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()) {
|
match is_useful(&cx, &seen, &PatStack::from_wild()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user