From 0ebc24043bb267cf77ddd6c1d8b7d5ad9f82444d Mon Sep 17 00:00:00 2001 From: adamrk Date: Thu, 25 Jun 2020 23:05:55 +0200 Subject: Infer type for slice wildcard patterns --- crates/ra_hir_ty/src/infer/pat.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_ty/src/infer') diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs index 23de2bd6b..4dd4f9802 100644 --- a/crates/ra_hir_ty/src/infer/pat.rs +++ b/crates/ra_hir_ty/src/infer/pat.rs @@ -184,7 +184,7 @@ impl<'a> InferenceContext<'a> { self.write_pat_ty(pat, bound_ty); return inner_ty; } - Pat::Slice { prefix, slice: _slice, suffix } => { + Pat::Slice { prefix, slice, suffix } => { let (container_ty, elem_ty) = match &expected { ty_app!(TypeCtor::Array, st) => (TypeCtor::Array, st.as_single().clone()), ty_app!(TypeCtor::Slice, st) => (TypeCtor::Slice, st.as_single().clone()), @@ -195,7 +195,12 @@ impl<'a> InferenceContext<'a> { self.infer_pat(*pat_id, &elem_ty, default_bm); } - Ty::apply_one(container_ty, elem_ty) + let pat_ty = Ty::apply_one(container_ty, elem_ty); + if let Some(slice_pat_id) = slice { + self.infer_pat(*slice_pat_id, &pat_ty, default_bm); + } + + pat_ty } Pat::Wild => expected.clone(), Pat::Range { start, end } => { -- cgit v1.2.3