diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-01 22:36:47 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-01 22:36:47 +0000 |
commit | b71fc18abe6e9572a3ca3ae18597fe05121095af (patch) | |
tree | 8d6624c9efe2626f52bec77a0513ee6335e76498 /crates/ra_hir_ty/src/infer | |
parent | ea67e2346e64a1a14206e6d0f163c6c2e19d0afb (diff) | |
parent | f5efa17515a543c1405ecad2caf93ed25052500e (diff) |
Merge #3387
3387: Type inference for slice patterns r=flodiebold a=JoshMcguigan
Fixes #3043
Notes to reviewer:
1. This only works if `expected` is `Ty::Apply`. I'm not sure of the implications of this.
1. This only works if the slice pattern only has a prefix. I think this means it doesn't work for subslice patterns, which are currently only available behind a feature flag.
Co-authored-by: Josh Mcguigan <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/infer')
-rw-r--r-- | crates/ra_hir_ty/src/infer/pat.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs index bf8ea192b..623e52599 100644 --- a/crates/ra_hir_ty/src/infer/pat.rs +++ b/crates/ra_hir_ty/src/infer/pat.rs | |||
@@ -185,6 +185,23 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
185 | self.write_pat_ty(pat, bound_ty); | 185 | self.write_pat_ty(pat, bound_ty); |
186 | return inner_ty; | 186 | return inner_ty; |
187 | } | 187 | } |
188 | Pat::Slice { prefix, slice: _slice, suffix } => { | ||
189 | let (container_ty, elem_ty) = match &expected { | ||
190 | ty_app!(TypeCtor::Array, st) => { | ||
191 | (TypeCtor::Array, st.as_single().clone()) | ||
192 | }, | ||
193 | ty_app!(TypeCtor::Slice, st) => { | ||
194 | (TypeCtor::Slice, st.as_single().clone()) | ||
195 | }, | ||
196 | _ => (TypeCtor::Slice, Ty::Unknown), | ||
197 | }; | ||
198 | |||
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) | ||
204 | } | ||
188 | _ => Ty::Unknown, | 205 | _ => Ty::Unknown, |
189 | }; | 206 | }; |
190 | // use a new type variable if we got Ty::Unknown here | 207 | // use a new type variable if we got Ty::Unknown here |