Fix box pattern inference panic

This commit is contained in:
Lukas Wirth 2021-03-21 18:18:25 +01:00
parent 1ae20d2b89
commit af50e8d955
3 changed files with 51 additions and 9 deletions

View file

@ -513,10 +513,10 @@ impl<'a> InferenceContext<'a> {
let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
if let Some(box_) = self.resolve_boxed_box() {
let mut sb =
Substitution::builder(generics(self.db.upcast(), box_.into()).len());
Substitution::build_for_generics(&generics(self.db.upcast(), box_.into()));
sb = sb.push(inner_ty);
match self.db.generic_defaults(box_.into()).as_ref() {
[_, alloc_ty, ..] if !alloc_ty.value.is_unknown() => {
match self.db.generic_defaults(box_.into()).get(1) {
Some(alloc_ty) if !alloc_ty.value.is_unknown() && sb.remaining() > 0 => {
sb = sb.push(alloc_ty.value.clone());
}
_ => (),