diff options
Diffstat (limited to 'crates/hir_ty/src/infer/pat.rs')
-rw-r--r-- | crates/hir_ty/src/infer/pat.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 474363709..f1316415f 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs | |||
@@ -35,7 +35,7 @@ impl<'a> InferenceContext<'a> { | |||
35 | } | 35 | } |
36 | self.unify(&ty, expected); | 36 | self.unify(&ty, expected); |
37 | 37 | ||
38 | let substs = ty.substs().cloned().unwrap_or_else(Substitution::empty); | 38 | let substs = ty.substs().cloned().unwrap_or_else(|| Substitution::empty(&Interner)); |
39 | 39 | ||
40 | let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); | 40 | let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); |
41 | let (pre, post) = match ellipsis { | 41 | let (pre, post) = match ellipsis { |
@@ -74,7 +74,7 @@ impl<'a> InferenceContext<'a> { | |||
74 | 74 | ||
75 | self.unify(&ty, expected); | 75 | self.unify(&ty, expected); |
76 | 76 | ||
77 | let substs = ty.substs().cloned().unwrap_or_else(Substitution::empty); | 77 | let substs = ty.substs().cloned().unwrap_or_else(|| Substitution::empty(&Interner)); |
78 | 78 | ||
79 | let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); | 79 | let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); |
80 | for subpat in subpats { | 80 | for subpat in subpats { |
@@ -134,7 +134,8 @@ impl<'a> InferenceContext<'a> { | |||
134 | }; | 134 | }; |
135 | let n_uncovered_patterns = expectations.len().saturating_sub(args.len()); | 135 | let n_uncovered_patterns = expectations.len().saturating_sub(args.len()); |
136 | let err_ty = self.err_ty(); | 136 | let err_ty = self.err_ty(); |
137 | let mut expectations_iter = expectations.iter().chain(repeat(&err_ty)); | 137 | let mut expectations_iter = |
138 | expectations.iter().map(|a| a.assert_ty_ref(&Interner)).chain(repeat(&err_ty)); | ||
138 | let mut infer_pat = |(&pat, ty)| self.infer_pat(pat, ty, default_bm); | 139 | let mut infer_pat = |(&pat, ty)| self.infer_pat(pat, ty, default_bm); |
139 | 140 | ||
140 | let mut inner_tys = Vec::with_capacity(n_uncovered_patterns + args.len()); | 141 | let mut inner_tys = Vec::with_capacity(n_uncovered_patterns + args.len()); |
@@ -142,7 +143,8 @@ impl<'a> InferenceContext<'a> { | |||
142 | inner_tys.extend(expectations_iter.by_ref().take(n_uncovered_patterns).cloned()); | 143 | inner_tys.extend(expectations_iter.by_ref().take(n_uncovered_patterns).cloned()); |
143 | inner_tys.extend(post.iter().zip(expectations_iter).map(infer_pat)); | 144 | inner_tys.extend(post.iter().zip(expectations_iter).map(infer_pat)); |
144 | 145 | ||
145 | TyKind::Tuple(inner_tys.len(), Substitution(inner_tys.into())).intern(&Interner) | 146 | TyKind::Tuple(inner_tys.len(), Substitution::from_iter(&Interner, inner_tys)) |
147 | .intern(&Interner) | ||
146 | } | 148 | } |
147 | Pat::Or(ref pats) => { | 149 | Pat::Or(ref pats) => { |
148 | if let Some((first_pat, rest)) = pats.split_first() { | 150 | if let Some((first_pat, rest)) = pats.split_first() { |
@@ -236,9 +238,10 @@ impl<'a> InferenceContext<'a> { | |||
236 | Pat::Box { inner } => match self.resolve_boxed_box() { | 238 | Pat::Box { inner } => match self.resolve_boxed_box() { |
237 | Some(box_adt) => { | 239 | Some(box_adt) => { |
238 | let (inner_ty, alloc_ty) = match expected.as_adt() { | 240 | let (inner_ty, alloc_ty) = match expected.as_adt() { |
239 | Some((adt, subst)) if adt == box_adt => { | 241 | Some((adt, subst)) if adt == box_adt => ( |
240 | (subst[0].clone(), subst.get(1).cloned()) | 242 | subst.at(&Interner, 0).assert_ty_ref(&Interner).clone(), |
241 | } | 243 | subst.interned(&Interner).get(1).and_then(|a| a.ty(&Interner).cloned()), |
244 | ), | ||
242 | _ => (self.result.standard_types.unknown.clone(), None), | 245 | _ => (self.result.standard_types.unknown.clone(), None), |
243 | }; | 246 | }; |
244 | 247 | ||