diff options
Diffstat (limited to 'crates/hir_ty/src/infer/pat.rs')
-rw-r--r-- | crates/hir_ty/src/infer/pat.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index afaf6b28b..12431ae07 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs | |||
@@ -13,8 +13,8 @@ use hir_expand::name::Name; | |||
13 | 13 | ||
14 | use super::{BindingMode, Expectation, InferenceContext}; | 14 | use super::{BindingMode, Expectation, InferenceContext}; |
15 | use crate::{ | 15 | use crate::{ |
16 | lower::lower_to_chalk_mutability, utils::variant_data, Interner, Substitution, Ty, TyBuilder, | 16 | lower::lower_to_chalk_mutability, static_lifetime, utils::variant_data, Interner, Substitution, |
17 | TyKind, | 17 | Ty, TyBuilder, TyExt, TyKind, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | impl<'a> InferenceContext<'a> { | 20 | impl<'a> InferenceContext<'a> { |
@@ -104,7 +104,7 @@ impl<'a> InferenceContext<'a> { | |||
104 | let body = Arc::clone(&self.body); // avoid borrow checker problem | 104 | let body = Arc::clone(&self.body); // avoid borrow checker problem |
105 | 105 | ||
106 | if is_non_ref_pat(&body, pat) { | 106 | if is_non_ref_pat(&body, pat) { |
107 | while let Some((inner, mutability)) = expected.as_reference() { | 107 | while let Some((inner, _lifetime, mutability)) = expected.as_reference() { |
108 | expected = inner; | 108 | expected = inner; |
109 | default_bm = match default_bm { | 109 | default_bm = match default_bm { |
110 | BindingMode::Move => BindingMode::Ref(mutability), | 110 | BindingMode::Move => BindingMode::Ref(mutability), |
@@ -162,7 +162,7 @@ impl<'a> InferenceContext<'a> { | |||
162 | Pat::Ref { pat, mutability } => { | 162 | Pat::Ref { pat, mutability } => { |
163 | let mutability = lower_to_chalk_mutability(*mutability); | 163 | let mutability = lower_to_chalk_mutability(*mutability); |
164 | let expectation = match expected.as_reference() { | 164 | let expectation = match expected.as_reference() { |
165 | Some((inner_ty, exp_mut)) => { | 165 | Some((inner_ty, _lifetime, exp_mut)) => { |
166 | if mutability != exp_mut { | 166 | if mutability != exp_mut { |
167 | // FIXME: emit type error? | 167 | // FIXME: emit type error? |
168 | } | 168 | } |
@@ -171,7 +171,7 @@ impl<'a> InferenceContext<'a> { | |||
171 | _ => self.result.standard_types.unknown.clone(), | 171 | _ => self.result.standard_types.unknown.clone(), |
172 | }; | 172 | }; |
173 | let subty = self.infer_pat(*pat, &expectation, default_bm); | 173 | let subty = self.infer_pat(*pat, &expectation, default_bm); |
174 | TyKind::Ref(mutability, subty).intern(&Interner) | 174 | TyKind::Ref(mutability, static_lifetime(), subty).intern(&Interner) |
175 | } | 175 | } |
176 | Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat( | 176 | Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat( |
177 | p.as_deref(), | 177 | p.as_deref(), |
@@ -204,7 +204,8 @@ impl<'a> InferenceContext<'a> { | |||
204 | 204 | ||
205 | let bound_ty = match mode { | 205 | let bound_ty = match mode { |
206 | BindingMode::Ref(mutability) => { | 206 | BindingMode::Ref(mutability) => { |
207 | TyKind::Ref(mutability, inner_ty.clone()).intern(&Interner) | 207 | TyKind::Ref(mutability, static_lifetime(), inner_ty.clone()) |
208 | .intern(&Interner) | ||
208 | } | 209 | } |
209 | BindingMode::Move => inner_ty.clone(), | 210 | BindingMode::Move => inner_ty.clone(), |
210 | }; | 211 | }; |
@@ -213,17 +214,20 @@ impl<'a> InferenceContext<'a> { | |||
213 | return inner_ty; | 214 | return inner_ty; |
214 | } | 215 | } |
215 | Pat::Slice { prefix, slice, suffix } => { | 216 | Pat::Slice { prefix, slice, suffix } => { |
216 | let (container_ty, elem_ty): (fn(_) -> _, _) = match expected.kind(&Interner) { | 217 | let elem_ty = match expected.kind(&Interner) { |
217 | TyKind::Array(st) => (TyKind::Array, st.clone()), | 218 | TyKind::Array(st, _) | TyKind::Slice(st) => st.clone(), |
218 | TyKind::Slice(st) => (TyKind::Slice, st.clone()), | 219 | _ => self.err_ty(), |
219 | _ => (TyKind::Slice, self.err_ty()), | ||
220 | }; | 220 | }; |
221 | 221 | ||
222 | for pat_id in prefix.iter().chain(suffix) { | 222 | for pat_id in prefix.iter().chain(suffix) { |
223 | self.infer_pat(*pat_id, &elem_ty, default_bm); | 223 | self.infer_pat(*pat_id, &elem_ty, default_bm); |
224 | } | 224 | } |
225 | 225 | ||
226 | let pat_ty = container_ty(elem_ty).intern(&Interner); | 226 | let pat_ty = match expected.kind(&Interner) { |
227 | TyKind::Array(_, const_) => TyKind::Array(elem_ty, const_.clone()), | ||
228 | _ => TyKind::Slice(elem_ty), | ||
229 | } | ||
230 | .intern(&Interner); | ||
227 | if let Some(slice_pat_id) = slice { | 231 | if let Some(slice_pat_id) = slice { |
228 | self.infer_pat(*slice_pat_id, &pat_ty, default_bm); | 232 | self.infer_pat(*slice_pat_id, &pat_ty, default_bm); |
229 | } | 233 | } |