diff options
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r-- | crates/ra_hir_ty/src/infer/pat.rs | 9 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/method_resolution.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/patterns.rs | 25 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/regression.rs | 2 |
4 files changed, 36 insertions, 3 deletions
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> { | |||
184 | self.write_pat_ty(pat, bound_ty); | 184 | self.write_pat_ty(pat, bound_ty); |
185 | return inner_ty; | 185 | return inner_ty; |
186 | } | 186 | } |
187 | Pat::Slice { prefix, slice: _slice, suffix } => { | 187 | Pat::Slice { prefix, slice, suffix } => { |
188 | let (container_ty, elem_ty) = match &expected { | 188 | let (container_ty, elem_ty) = match &expected { |
189 | ty_app!(TypeCtor::Array, st) => (TypeCtor::Array, st.as_single().clone()), | 189 | ty_app!(TypeCtor::Array, st) => (TypeCtor::Array, st.as_single().clone()), |
190 | ty_app!(TypeCtor::Slice, st) => (TypeCtor::Slice, st.as_single().clone()), | 190 | ty_app!(TypeCtor::Slice, st) => (TypeCtor::Slice, st.as_single().clone()), |
@@ -195,7 +195,12 @@ impl<'a> InferenceContext<'a> { | |||
195 | self.infer_pat(*pat_id, &elem_ty, default_bm); | 195 | self.infer_pat(*pat_id, &elem_ty, default_bm); |
196 | } | 196 | } |
197 | 197 | ||
198 | Ty::apply_one(container_ty, elem_ty) | 198 | let pat_ty = Ty::apply_one(container_ty, elem_ty); |
199 | if let Some(slice_pat_id) = slice { | ||
200 | self.infer_pat(*slice_pat_id, &pat_ty, default_bm); | ||
201 | } | ||
202 | |||
203 | pat_ty | ||
199 | } | 204 | } |
200 | Pat::Wild => expected.clone(), | 205 | Pat::Wild => expected.clone(), |
201 | Pat::Range { start, end } => { | 206 | Pat::Range { start, end } => { |
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 8b59a8bd6..c19519cf1 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs | |||
@@ -281,6 +281,7 @@ pub fn iterate_method_candidates<T>( | |||
281 | name, | 281 | name, |
282 | mode, | 282 | mode, |
283 | &mut |ty, item| { | 283 | &mut |ty, item| { |
284 | assert!(slot.is_none()); | ||
284 | slot = callback(ty, item); | 285 | slot = callback(ty, item); |
285 | slot.is_some() | 286 | slot.is_some() |
286 | }, | 287 | }, |
@@ -288,7 +289,7 @@ pub fn iterate_method_candidates<T>( | |||
288 | slot | 289 | slot |
289 | } | 290 | } |
290 | 291 | ||
291 | pub fn iterate_method_candidates_impl( | 292 | fn iterate_method_candidates_impl( |
292 | ty: &Canonical<Ty>, | 293 | ty: &Canonical<Ty>, |
293 | db: &dyn HirDatabase, | 294 | db: &dyn HirDatabase, |
294 | env: Arc<TraitEnvironment>, | 295 | env: Arc<TraitEnvironment>, |
diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs index e5ef241ca..f937426bd 100644 --- a/crates/ra_hir_ty/src/tests/patterns.rs +++ b/crates/ra_hir_ty/src/tests/patterns.rs | |||
@@ -627,3 +627,28 @@ fn test() { | |||
627 | "### | 627 | "### |
628 | ); | 628 | ); |
629 | } | 629 | } |
630 | |||
631 | #[test] | ||
632 | fn slice_tail_pattern() { | ||
633 | assert_snapshot!( | ||
634 | infer(r#" | ||
635 | fn foo(params: &[i32]) { | ||
636 | match params { | ||
637 | [head, tail @ ..] => { | ||
638 | } | ||
639 | } | ||
640 | } | ||
641 | "#), | ||
642 | @r###" | ||
643 | 7..13 'params': &[i32] | ||
644 | 23..92 '{ ... } }': () | ||
645 | 29..90 'match ... }': () | ||
646 | 35..41 'params': &[i32] | ||
647 | 52..69 '[head,... @ ..]': [i32] | ||
648 | 53..57 'head': &i32 | ||
649 | 59..68 'tail @ ..': &[i32] | ||
650 | 66..68 '..': [i32] | ||
651 | 73..84 '{ }': () | ||
652 | "### | ||
653 | ); | ||
654 | } | ||
diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs index eedaa27ba..aa37326df 100644 --- a/crates/ra_hir_ty/src/tests/regression.rs +++ b/crates/ra_hir_ty/src/tests/regression.rs | |||
@@ -500,6 +500,8 @@ fn foo(params: &[usize]) { | |||
500 | 31..78 'match ... }': () | 500 | 31..78 'match ... }': () |
501 | 37..43 'params': &[usize] | 501 | 37..43 'params': &[usize] |
502 | 54..66 '[ps @ .., _]': [usize] | 502 | 54..66 '[ps @ .., _]': [usize] |
503 | 55..62 'ps @ ..': &[usize] | ||
504 | 60..62 '..': [usize] | ||
503 | 64..65 '_': usize | 505 | 64..65 '_': usize |
504 | 70..72 '{}': () | 506 | 70..72 '{}': () |
505 | "### | 507 | "### |