From b9ef7a6b987eea4b0b14298fbbe44d912806f50f Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Sun, 1 Mar 2020 12:13:05 -0800 Subject: remove match statement, handle suffix --- crates/ra_hir_ty/src/infer/pat.rs | 21 +++++++++------------ crates/ra_hir_ty/src/tests/patterns.rs | 4 ++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs index 3fe1a4abb..06b09af82 100644 --- a/crates/ra_hir_ty/src/infer/pat.rs +++ b/crates/ra_hir_ty/src/infer/pat.rs @@ -185,21 +185,18 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.write_pat_ty(pat, bound_ty); return inner_ty; } - Pat::Slice { prefix, slice, suffix } => { - if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Slice, parameters }) = expected { - match (prefix.as_slice(), slice, suffix.as_slice()) { - (prefix_pat_ids, None, []) => { - for pat_id in prefix_pat_ids { - self.infer_pat(*pat_id, parameters.as_single(), default_bm); - } - - Ty::apply_one(TypeCtor::Slice, parameters.as_single().clone()) - }, - _ => Ty::Unknown, + Pat::Slice { prefix, slice: _slice, suffix } => { + let ty = if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Slice, parameters }) = expected { + for pat_id in prefix.iter().chain(suffix) { + self.infer_pat(*pat_id, parameters.as_single(), default_bm); } + + parameters.as_single().clone() } else { Ty::Unknown - } + }; + + Ty::apply_one(TypeCtor::Slice, ty) } _ => Ty::Unknown, }; diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs index 6a9413521..d8e95112f 100644 --- a/crates/ra_hir_ty/src/tests/patterns.rs +++ b/crates/ra_hir_ty/src/tests/patterns.rs @@ -53,8 +53,8 @@ fn test(x: &i32) { [140; 141) 'g': {unknown} [144; 145) 'e': {unknown} [158; 205) 'if let... }': () - [165; 170) '[val]': {unknown} - [173; 176) 'opt': {unknown} + [165; 170) '[val]': [{unknown}] + [173; 176) 'opt': [{unknown}] [177; 205) '{ ... }': () [191; 192) 'h': {unknown} [195; 198) 'val': {unknown} -- cgit v1.2.3