From d1338354ca7afae7088f84756ed103ea94ce82f9 Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Fri, 10 Apr 2020 20:14:53 -0700 Subject: fix match arm false positive --- crates/ra_hir_ty/src/expr.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir_ty/src/expr.rs') 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> { 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 @@ -191,8 +185,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()) { -- cgit v1.2.3