aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/infer.rs')
-rw-r--r--crates/hir_ty/src/infer.rs34
1 files changed, 17 insertions, 17 deletions
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs
index 8cfc84b86..ab742e203 100644
--- a/crates/hir_ty/src/infer.rs
+++ b/crates/hir_ty/src/infer.rs
@@ -273,7 +273,7 @@ impl<'a> InferenceContext<'a> {
273 } 273 }
274 274
275 fn err_ty(&self) -> Ty { 275 fn err_ty(&self) -> Ty {
276 TyKind::Error.intern(&Interner) 276 self.result.standard_types.unknown.clone()
277 } 277 }
278 278
279 fn resolve_all(mut self) -> InferenceResult { 279 fn resolve_all(mut self) -> InferenceResult {
@@ -284,12 +284,14 @@ impl<'a> InferenceContext<'a> {
284 self.table.propagate_diverging_flag(); 284 self.table.propagate_diverging_flag();
285 let mut result = std::mem::take(&mut self.result); 285 let mut result = std::mem::take(&mut self.result);
286 for ty in result.type_of_expr.values_mut() { 286 for ty in result.type_of_expr.values_mut() {
287 let resolved = self.table.resolve_ty_completely(ty.clone()); 287 *ty = self.table.resolve_ty_completely(ty.clone());
288 *ty = resolved;
289 } 288 }
290 for ty in result.type_of_pat.values_mut() { 289 for ty in result.type_of_pat.values_mut() {
291 let resolved = self.table.resolve_ty_completely(ty.clone()); 290 *ty = self.table.resolve_ty_completely(ty.clone());
292 *ty = resolved; 291 }
292 for mismatch in result.type_mismatches.values_mut() {
293 mismatch.expected = self.table.resolve_ty_completely(mismatch.expected.clone());
294 mismatch.actual = self.table.resolve_ty_completely(mismatch.actual.clone());
293 } 295 }
294 result 296 result
295 } 297 }
@@ -343,6 +345,14 @@ impl<'a> InferenceContext<'a> {
343 fn insert_type_vars_shallow(&mut self, ty: Ty) -> Ty { 345 fn insert_type_vars_shallow(&mut self, ty: Ty) -> Ty {
344 match ty.kind(&Interner) { 346 match ty.kind(&Interner) {
345 TyKind::Error => self.table.new_type_var(), 347 TyKind::Error => self.table.new_type_var(),
348 TyKind::InferenceVar(..) => {
349 let ty_resolved = self.resolve_ty_shallow(&ty);
350 if ty_resolved.is_unknown() {
351 self.table.new_type_var()
352 } else {
353 ty
354 }
355 }
346 _ => ty, 356 _ => ty,
347 } 357 }
348 } 358 }
@@ -371,18 +381,8 @@ impl<'a> InferenceContext<'a> {
371 self.table.unify_inner(ty1, ty2) 381 self.table.unify_inner(ty1, ty2)
372 } 382 }
373 383
374 // FIXME get rid of this, instead resolve shallowly where necessary
375 /// Resolves the type as far as currently possible, replacing type variables
376 /// by their known types. All types returned by the infer_* functions should
377 /// be resolved as far as possible, i.e. contain no type variables with
378 /// known type.
379 fn resolve_ty_as_possible(&mut self, ty: Ty) -> Ty {
380 self.resolve_obligations_as_possible();
381
382 self.table.resolve_ty_as_possible(ty)
383 }
384
385 fn resolve_ty_shallow(&mut self, ty: &Ty) -> Ty { 384 fn resolve_ty_shallow(&mut self, ty: &Ty) -> Ty {
385 self.resolve_obligations_as_possible();
386 self.table.resolve_ty_shallow(ty) 386 self.table.resolve_ty_shallow(ty)
387 } 387 }
388 388
@@ -416,7 +416,7 @@ impl<'a> InferenceContext<'a> {
416 }; 416 };
417 self.push_obligation(trait_ref.cast(&Interner)); 417 self.push_obligation(trait_ref.cast(&Interner));
418 self.push_obligation(alias_eq.cast(&Interner)); 418 self.push_obligation(alias_eq.cast(&Interner));
419 self.resolve_ty_as_possible(ty) 419 ty
420 } 420 }
421 None => self.err_ty(), 421 None => self.err_ty(),
422 } 422 }