aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_ty/src/infer/pat.rs8
-rw-r--r--crates/ra_hir_ty/src/tests/patterns.rs33
2 files changed, 29 insertions, 12 deletions
diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs
index b991720ff..3fe1a4abb 100644
--- a/crates/ra_hir_ty/src/infer/pat.rs
+++ b/crates/ra_hir_ty/src/infer/pat.rs
@@ -188,10 +188,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
188 Pat::Slice { prefix, slice, suffix } => { 188 Pat::Slice { prefix, slice, suffix } => {
189 if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Slice, parameters }) = expected { 189 if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Slice, parameters }) = expected {
190 match (prefix.as_slice(), slice, suffix.as_slice()) { 190 match (prefix.as_slice(), slice, suffix.as_slice()) {
191 ([prefix_pat_id], None, []) => { 191 (prefix_pat_ids, None, []) => {
192 let ty = self.infer_pat(*prefix_pat_id, &parameters.0[0], default_bm); 192 for pat_id in prefix_pat_ids {
193 self.infer_pat(*pat_id, parameters.as_single(), default_bm);
194 }
193 195
194 Ty::apply_one(TypeCtor::Slice, ty) 196 Ty::apply_one(TypeCtor::Slice, parameters.as_single().clone())
195 }, 197 },
196 _ => Ty::Unknown, 198 _ => Ty::Unknown,
197 } 199 }
diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs
index fdc9dd180..6a9413521 100644
--- a/crates/ra_hir_ty/src/tests/patterns.rs
+++ b/crates/ra_hir_ty/src/tests/patterns.rs
@@ -143,28 +143,43 @@ fn infer_pattern_match_slice() {
143fn test() { 143fn test() {
144 let slice: &[f64] = &[0.0]; 144 let slice: &[f64] = &[0.0];
145 match slice { 145 match slice {
146 &[] => {},
146 &[a] => { 147 &[a] => {
147 a; 148 a;
149 },
150 &[b, c] => {
151 b;
152 c;
148 } 153 }
149 _ => {} 154 _ => {}
150 } 155 }
151} 156}
152"#), 157"#),
153 @r###" 158 @r###"
154 [11; 129) '{ ... } }': () 159 [11; 210) '{ ... } }': ()
155 [21; 26) 'slice': &[f64] 160 [21; 26) 'slice': &[f64]
156 [37; 43) '&[0.0]': &[f64; _] 161 [37; 43) '&[0.0]': &[f64; _]
157 [38; 43) '[0.0]': [f64; _] 162 [38; 43) '[0.0]': [f64; _]
158 [39; 42) '0.0': f64 163 [39; 42) '0.0': f64
159 [49; 127) 'match ... }': () 164 [49; 208) 'match ... }': ()
160 [55; 60) 'slice': &[f64] 165 [55; 60) 'slice': &[f64]
161 [71; 75) '&[a]': &[f64] 166 [71; 74) '&[]': &[f64]
162 [72; 75) '[a]': [f64] 167 [72; 74) '[]': [f64]
163 [73; 74) 'a': f64 168 [78; 80) '{}': ()
164 [79; 105) '{ ... }': () 169 [90; 94) '&[a]': &[f64]
165 [93; 94) 'a': f64 170 [91; 94) '[a]': [f64]
166 [114; 115) '_': &[f64] 171 [92; 93) 'a': f64
167 [119; 121) '{}': () 172 [98; 124) '{ ... }': ()
173 [112; 113) 'a': f64
174 [134; 141) '&[b, c]': &[f64]
175 [135; 141) '[b, c]': [f64]
176 [136; 137) 'b': f64
177 [139; 140) 'c': f64
178 [145; 186) '{ ... }': ()
179 [159; 160) 'b': f64
180 [174; 175) 'c': f64
181 [195; 196) '_': &[f64]
182 [200; 202) '{}': ()
168 "### 183 "###
169 ); 184 );
170} 185}