aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer/coerce.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/infer/coerce.rs')
-rw-r--r--crates/hir_ty/src/infer/coerce.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs
index 03dd6ae76..40b4db926 100644
--- a/crates/hir_ty/src/infer/coerce.rs
+++ b/crates/hir_ty/src/infer/coerce.rs
@@ -6,11 +6,11 @@
6//! librustc_typeck/check/coercion.rs. 6//! librustc_typeck/check/coercion.rs.
7 7
8use chalk_ir::{cast::Cast, Mutability, TyVariableKind}; 8use chalk_ir::{cast::Cast, Mutability, TyVariableKind};
9use hir_def::lang_item::LangItemTarget; 9use hir_def::{expr::ExprId, lang_item::LangItemTarget};
10 10
11use crate::{ 11use crate::{
12 autoderef, static_lifetime, Canonical, DomainGoal, FnPointer, FnSig, Interner, Solution, 12 autoderef, infer::TypeMismatch, static_lifetime, Canonical, DomainGoal, FnPointer, FnSig,
13 Substitution, Ty, TyBuilder, TyExt, TyKind, 13 Interner, Solution, Substitution, Ty, TyBuilder, TyExt, TyKind,
14}; 14};
15 15
16use super::{InEnvironment, InferOk, InferResult, InferenceContext, TypeError}; 16use super::{InEnvironment, InferOk, InferResult, InferenceContext, TypeError};
@@ -40,7 +40,7 @@ impl<'a> InferenceContext<'a> {
40 /// coerce both to function pointers; 40 /// coerce both to function pointers;
41 /// - if we were concerned with lifetime subtyping, we'd need to look for a 41 /// - if we were concerned with lifetime subtyping, we'd need to look for a
42 /// least upper bound. 42 /// least upper bound.
43 pub(super) fn coerce_merge_branch(&mut self, ty1: &Ty, ty2: &Ty) -> Ty { 43 pub(super) fn coerce_merge_branch(&mut self, id: Option<ExprId>, ty1: &Ty, ty2: &Ty) -> Ty {
44 let ty1 = self.resolve_ty_shallow(ty1); 44 let ty1 = self.resolve_ty_shallow(ty1);
45 let ty2 = self.resolve_ty_shallow(ty2); 45 let ty2 = self.resolve_ty_shallow(ty2);
46 // Special case: two function types. Try to coerce both to 46 // Special case: two function types. Try to coerce both to
@@ -80,7 +80,11 @@ impl<'a> InferenceContext<'a> {
80 } else if self.coerce(&ty1, &ty2) { 80 } else if self.coerce(&ty1, &ty2) {
81 ty2.clone() 81 ty2.clone()
82 } else { 82 } else {
83 // TODO record a type mismatch 83 if let Some(id) = id {
84 self.result
85 .type_mismatches
86 .insert(id.into(), TypeMismatch { expected: ty1.clone(), actual: ty2.clone() });
87 }
84 cov_mark::hit!(coerce_merge_fail_fallback); 88 cov_mark::hit!(coerce_merge_fail_fallback);
85 ty1.clone() 89 ty1.clone()
86 } 90 }