remove match statement, handle suffix

This commit is contained in:
Josh Mcguigan 2020-03-01 12:13:05 -08:00
parent d0e282f6b1
commit b9ef7a6b98
2 changed files with 11 additions and 14 deletions

View file

@ -185,21 +185,18 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
self.write_pat_ty(pat, bound_ty);
return inner_ty;
}
Pat::Slice { prefix, slice, suffix } => {
if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Slice, parameters }) = expected {
match (prefix.as_slice(), slice, suffix.as_slice()) {
(prefix_pat_ids, None, []) => {
for pat_id in prefix_pat_ids {
self.infer_pat(*pat_id, parameters.as_single(), default_bm);
}
Ty::apply_one(TypeCtor::Slice, parameters.as_single().clone())
},
_ => Ty::Unknown,
Pat::Slice { prefix, slice: _slice, suffix } => {
let ty = if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Slice, parameters }) = expected {
for pat_id in prefix.iter().chain(suffix) {
self.infer_pat(*pat_id, parameters.as_single(), default_bm);
}
parameters.as_single().clone()
} else {
Ty::Unknown
}
};
Ty::apply_one(TypeCtor::Slice, ty)
}
_ => Ty::Unknown,
};

View file

@ -53,8 +53,8 @@ fn test(x: &i32) {
[140; 141) 'g': {unknown}
[144; 145) 'e': {unknown}
[158; 205) 'if let... }': ()
[165; 170) '[val]': {unknown}
[173; 176) 'opt': {unknown}
[165; 170) '[val]': [{unknown}]
[173; 176) 'opt': [{unknown}]
[177; 205) '{ ... }': ()
[191; 192) 'h': {unknown}
[195; 198) 'val': {unknown}