diff options
author | Florian Diebold <[email protected]> | 2021-05-21 16:48:15 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-05-21 17:23:03 +0100 |
commit | 6e5637983c155b2914647bb5e437337a44a63a7d (patch) | |
tree | 7329b76bdc2424075fafcac3108d70f1d8bae82c /crates/hir_ty/src/infer/coerce.rs | |
parent | 556c9cebdb91278702263df4ac8c99ec24ab331a (diff) |
Record type mismatches for failed coercions in match etc.
Diffstat (limited to 'crates/hir_ty/src/infer/coerce.rs')
-rw-r--r-- | crates/hir_ty/src/infer/coerce.rs | 14 |
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 | ||
8 | use chalk_ir::{cast::Cast, Mutability, TyVariableKind}; | 8 | use chalk_ir::{cast::Cast, Mutability, TyVariableKind}; |
9 | use hir_def::lang_item::LangItemTarget; | 9 | use hir_def::{expr::ExprId, lang_item::LangItemTarget}; |
10 | 10 | ||
11 | use crate::{ | 11 | use 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 | ||
16 | use super::{InEnvironment, InferOk, InferResult, InferenceContext, TypeError}; | 16 | use 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 | } |