Skip to content

Commit b9ef7a6

Browse files
committed
remove match statement, handle suffix
1 parent d0e282f commit b9ef7a6

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

crates/ra_hir_ty/src/infer/pat.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,18 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
185185
self.write_pat_ty(pat, bound_ty);
186186
return inner_ty;
187187
}
188-
Pat::Slice { prefix, slice, suffix } => {
189-
if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Slice, parameters }) = expected {
190-
match (prefix.as_slice(), slice, suffix.as_slice()) {
191-
(prefix_pat_ids, None, []) => {
192-
for pat_id in prefix_pat_ids {
193-
self.infer_pat(*pat_id, parameters.as_single(), default_bm);
194-
}
195-
196-
Ty::apply_one(TypeCtor::Slice, parameters.as_single().clone())
197-
},
198-
_ => Ty::Unknown,
188+
Pat::Slice { prefix, slice: _slice, suffix } => {
189+
let ty = if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Slice, parameters }) = expected {
190+
for pat_id in prefix.iter().chain(suffix) {
191+
self.infer_pat(*pat_id, parameters.as_single(), default_bm);
199192
}
193+
194+
parameters.as_single().clone()
200195
} else {
201196
Ty::Unknown
202-
}
197+
};
198+
199+
Ty::apply_one(TypeCtor::Slice, ty)
203200
}
204201
_ => Ty::Unknown,
205202
};

crates/ra_hir_ty/src/tests/patterns.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ fn test(x: &i32) {
5353
[140; 141) 'g': {unknown}
5454
[144; 145) 'e': {unknown}
5555
[158; 205) 'if let... }': ()
56-
[165; 170) '[val]': {unknown}
57-
[173; 176) 'opt': {unknown}
56+
[165; 170) '[val]': [{unknown}]
57+
[173; 176) 'opt': [{unknown}]
5858
[177; 205) '{ ... }': ()
5959
[191; 192) 'h': {unknown}
6060
[195; 198) 'val': {unknown}

0 commit comments

Comments
 (0)