From 472317c00870c007f552cde1f3c490e04f29919a Mon Sep 17 00:00:00 2001 From: Dawer <7803845+iDawer@users.noreply.github.com> Date: Wed, 19 May 2021 09:23:16 +0500 Subject: internal: Record mismatches of pattern types. --- crates/hir_ty/src/infer/expr.rs | 9 +++++---- crates/hir_ty/src/infer/pat.rs | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'crates/hir_ty/src/infer') diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index b6b5a1b75..7278faeec 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -42,7 +42,7 @@ impl<'a> InferenceContext<'a> { let could_unify = self.unify(&ty, &expected.ty); if !could_unify { self.result.type_mismatches.insert( - tgt_expr, + tgt_expr.into(), TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() }, ); } @@ -54,9 +54,10 @@ impl<'a> InferenceContext<'a> { pub(super) fn infer_expr_coerce(&mut self, expr: ExprId, expected: &Expectation) -> Ty { let ty = self.infer_expr_inner(expr, &expected); let ty = if !self.coerce(&ty, &expected.coercion_target()) { - self.result - .type_mismatches - .insert(expr, TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() }); + self.result.type_mismatches.insert( + expr.into(), + TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() }, + ); // Return actual type when type mismatch. // This is needed for diagnostic when return type mismatch. ty diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 60b94a642..b15f4977d 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs @@ -10,7 +10,7 @@ use hir_def::{ }; use hir_expand::name::Name; -use super::{BindingMode, Expectation, InferenceContext}; +use super::{BindingMode, Expectation, InferenceContext, TypeMismatch}; use crate::{ lower::lower_to_chalk_mutability, static_lifetime, Interner, Substitution, Ty, TyBuilder, TyExt, TyKind, @@ -266,7 +266,10 @@ impl<'a> InferenceContext<'a> { // use a new type variable if we got error type here let ty = self.insert_type_vars_shallow(ty); if !self.unify(&ty, expected) { - // FIXME record mismatch, we need to change the type of self.type_mismatches for that + self.result.type_mismatches.insert( + pat.into(), + TypeMismatch { expected: expected.clone(), actual: ty.clone() }, + ); } let ty = self.resolve_ty_as_possible(ty); self.write_pat_ty(pat, ty.clone()); -- cgit v1.2.3