aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/infer
diff options
context:
space:
mode:
authorJosh Mcguigan <[email protected]>2020-03-01 22:02:32 +0000
committerJosh Mcguigan <[email protected]>2020-03-01 22:02:32 +0000
commitf5efa17515a543c1405ecad2caf93ed25052500e (patch)
treecb91b80bee65f81bb408ab0c1f1240733f3156f1 /crates/ra_hir_ty/src/infer
parentb9ef7a6b987eea4b0b14298fbbe44d912806f50f (diff)
handle array pattern matching type inference
Diffstat (limited to 'crates/ra_hir_ty/src/infer')
-rw-r--r--crates/ra_hir_ty/src/infer/pat.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs
index 06b09af82..623e52599 100644
--- a/crates/ra_hir_ty/src/infer/pat.rs
+++ b/crates/ra_hir_ty/src/infer/pat.rs
@@ -12,7 +12,7 @@ use hir_expand::name::Name;
12use test_utils::tested_by; 12use test_utils::tested_by;
13 13
14use super::{BindingMode, InferenceContext}; 14use super::{BindingMode, InferenceContext};
15use crate::{db::HirDatabase, utils::variant_data, Substs, Ty, TypeCtor, ApplicationTy}; 15use crate::{db::HirDatabase, utils::variant_data, Substs, Ty, TypeCtor};
16 16
17impl<'a, D: HirDatabase> InferenceContext<'a, D> { 17impl<'a, D: HirDatabase> InferenceContext<'a, D> {
18 fn infer_tuple_struct_pat( 18 fn infer_tuple_struct_pat(
@@ -186,17 +186,21 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
186 return inner_ty; 186 return inner_ty;
187 } 187 }
188 Pat::Slice { prefix, slice: _slice, suffix } => { 188 Pat::Slice { prefix, slice: _slice, suffix } => {
189 let ty = if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Slice, parameters }) = expected { 189 let (container_ty, elem_ty) = match &expected {
190 for pat_id in prefix.iter().chain(suffix) { 190 ty_app!(TypeCtor::Array, st) => {
191 self.infer_pat(*pat_id, parameters.as_single(), default_bm); 191 (TypeCtor::Array, st.as_single().clone())
192 } 192 },
193 193 ty_app!(TypeCtor::Slice, st) => {
194 parameters.as_single().clone() 194 (TypeCtor::Slice, st.as_single().clone())
195 } else { 195 },
196 Ty::Unknown 196 _ => (TypeCtor::Slice, Ty::Unknown),
197 }; 197 };
198 198
199 Ty::apply_one(TypeCtor::Slice, ty) 199 for pat_id in prefix.iter().chain(suffix) {
200 self.infer_pat(*pat_id, &elem_ty, default_bm);
201 }
202
203 Ty::apply_one(container_ty, elem_ty)
200 } 204 }
201 _ => Ty::Unknown, 205 _ => Ty::Unknown,
202 }; 206 };