From cd2347e13269076cc52bbffc9cc2e370c831893e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Thu, 7 Mar 2024 18:40:41 +0200 Subject: [PATCH] Skip match diagnostics for partially unknown types --- crates/hir-ty/src/diagnostics/expr.rs | 5 ++++- .../src/handlers/missing_match_arms.rs | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/hir-ty/src/diagnostics/expr.rs b/crates/hir-ty/src/diagnostics/expr.rs index 69205f8fddf..67cfbc294df 100644 --- a/crates/hir-ty/src/diagnostics/expr.rs +++ b/crates/hir-ty/src/diagnostics/expr.rs @@ -182,7 +182,7 @@ impl ExprValidator { db: &dyn HirDatabase, ) { let scrut_ty = &self.infer[scrutinee_expr]; - if scrut_ty.is_unknown() { + if scrut_ty.contains_unknown() { return; } @@ -267,6 +267,9 @@ impl ExprValidator { }; let Some(initializer) = initializer else { continue }; let ty = &self.infer[initializer]; + if ty.contains_unknown() { + continue; + } let mut have_errors = false; let deconstructed_pat = self.lower_pattern(&cx, pat, db, &mut have_errors); diff --git a/crates/ide-diagnostics/src/handlers/missing_match_arms.rs b/crates/ide-diagnostics/src/handlers/missing_match_arms.rs index 8596f5792e0..67daa172b27 100644 --- a/crates/ide-diagnostics/src/handlers/missing_match_arms.rs +++ b/crates/ide-diagnostics/src/handlers/missing_match_arms.rs @@ -597,21 +597,19 @@ fn bang(never: !) { #[test] fn unknown_type() { - cov_mark::check_count!(validate_match_bailed_out, 1); - - check_diagnostics( + check_diagnostics_no_bails( r#" enum Option { Some(T), None } #[allow(unused)] fn main() { // `Never` is deliberately not defined so that it's an uninferred type. + // We ignore these to avoid triggering bugs in the analysis. match Option::::None { None => (), Some(never) => match never {}, } match Option::::None { - //^^^^^^^^^^^^^^^^^^^^^ error: missing match arm: `None` not covered Option::Some(_never) => {}, } } @@ -619,6 +617,18 @@ fn main() { ); } + #[test] + fn arity_mismatch_issue_16746() { + check_diagnostics_with_disabled( + r#" +fn main() { + let (a, ) = (0, 0); +} +"#, + &["E0308"], + ); + } + #[test] fn tuple_of_bools_with_ellipsis_at_end_missing_arm() { check_diagnostics_no_bails(