From 2abb4c99fe8a5839fe2910e90f3471e6308f6229 Mon Sep 17 00:00:00 2001 From: Dawer <7803845+iDawer@users.noreply.github.com> Date: Sat, 15 May 2021 00:09:17 +0500 Subject: Fix false positive "Missing match arm". --- crates/hir_ty/src/diagnostics/match_check.rs | 1 + crates/hir_ty/src/infer/pat.rs | 9 +++++---- crates/hir_ty/src/tests/patterns.rs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/diagnostics/match_check.rs b/crates/hir_ty/src/diagnostics/match_check.rs index e9762622f..6ee0529c6 100644 --- a/crates/hir_ty/src/diagnostics/match_check.rs +++ b/crates/hir_ty/src/diagnostics/match_check.rs @@ -1119,6 +1119,7 @@ fn main() { (true, false, true) => (), (true) => (), } + match (true, false) { (true,) => {} } match (0) { () => () } match Unresolved::Bar { Unresolved::Baz => () } } diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index aea354cde..60b94a642 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs @@ -126,11 +126,12 @@ impl<'a> InferenceContext<'a> { _ => &[], }; - let (pre, post) = match ellipsis { - Some(idx) => args.split_at(idx), - None => (&args[..], &[][..]), + let ((pre, post), n_uncovered_patterns) = match ellipsis { + Some(idx) => { + (args.split_at(idx), expectations.len().saturating_sub(args.len())) + } + None => ((&args[..], &[][..]), 0), }; - let n_uncovered_patterns = expectations.len().saturating_sub(args.len()); let err_ty = self.err_ty(); let mut expectations_iter = expectations.iter().map(|a| a.assert_ty_ref(&Interner)).chain(repeat(&err_ty)); diff --git a/crates/hir_ty/src/tests/patterns.rs b/crates/hir_ty/src/tests/patterns.rs index 33305f208..a0a7b4d0b 100644 --- a/crates/hir_ty/src/tests/patterns.rs +++ b/crates/hir_ty/src/tests/patterns.rs @@ -732,7 +732,7 @@ fn foo(tuple: (u8, i16, f32)) { 111..112 'a': u8 114..115 'b': i16 124..126 '{}': () - 136..142 '(a, b)': (u8, i16, f32) + 136..142 '(a, b)': (u8, i16) 137..138 'a': u8 140..141 'b': i16 146..161 '{/*too short*/}': () -- cgit v1.2.3