aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/infer
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-12-01 21:14:28 +0000
committerFlorian Diebold <[email protected]>2019-12-02 18:33:13 +0000
commit456d52fdfa8525af2a54e76ee5300f0a40ef582a (patch)
treee8cd093624ac3ccc9926856dc8db0d4daa0d0b8a /crates/ra_hir_ty/src/infer
parent599dab59824b164b1c24e2e51adeae1ac1307964 (diff)
Check receiver type properly
Diffstat (limited to 'crates/ra_hir_ty/src/infer')
-rw-r--r--crates/ra_hir_ty/src/infer/coerce.rs2
-rw-r--r--crates/ra_hir_ty/src/infer/unify.rs20
2 files changed, 13 insertions, 9 deletions
diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs
index 9bfc701cd..9daa77cfa 100644
--- a/crates/ra_hir_ty/src/infer/coerce.rs
+++ b/crates/ra_hir_ty/src/infer/coerce.rs
@@ -10,7 +10,7 @@ use test_utils::tested_by;
10 10
11use crate::{autoderef, db::HirDatabase, Substs, Ty, TypeCtor, TypeWalk}; 11use crate::{autoderef, db::HirDatabase, Substs, Ty, TypeCtor, TypeWalk};
12 12
13use super::{InEnvironment, InferTy, InferenceContext, unify::TypeVarValue}; 13use super::{unify::TypeVarValue, InEnvironment, InferTy, InferenceContext};
14 14
15impl<'a, D: HirDatabase> InferenceContext<'a, D> { 15impl<'a, D: HirDatabase> InferenceContext<'a, D> {
16 /// Unify two types, but may coerce the first one to the second one 16 /// Unify two types, but may coerce the first one to the second one
diff --git a/crates/ra_hir_ty/src/infer/unify.rs b/crates/ra_hir_ty/src/infer/unify.rs
index ff50138f5..8ed2a6090 100644
--- a/crates/ra_hir_ty/src/infer/unify.rs
+++ b/crates/ra_hir_ty/src/infer/unify.rs
@@ -167,13 +167,19 @@ impl<T> Canonicalized<T> {
167 } 167 }
168} 168}
169 169
170pub fn unify(ty1: Canonical<&Ty>, ty2: &Ty) -> Substs { 170pub fn unify(ty1: Canonical<&Ty>, ty2: &Ty) -> Option<Substs> {
171 let mut table = InferenceTable::new(); 171 let mut table = InferenceTable::new();
172 let vars = Substs::builder(ty1.num_vars) 172 let vars =
173 .fill(std::iter::repeat_with(|| table.new_type_var())).build(); 173 Substs::builder(ty1.num_vars).fill(std::iter::repeat_with(|| table.new_type_var())).build();
174 let ty_with_vars = ty1.value.clone().subst_bound_vars(&vars); 174 let ty_with_vars = ty1.value.clone().subst_bound_vars(&vars);
175 table.unify(&ty_with_vars, ty2); 175 if !table.unify(&ty_with_vars, ty2) {
176 Substs::builder(ty1.num_vars).fill(vars.iter().map(|v| table.resolve_ty_completely(v.clone()))).build() 176 return None;
177 }
178 Some(
179 Substs::builder(ty1.num_vars)
180 .fill(vars.iter().map(|v| table.resolve_ty_completely(v.clone())))
181 .build(),
182 )
177} 183}
178 184
179#[derive(Clone, Debug)] 185#[derive(Clone, Debug)]
@@ -183,9 +189,7 @@ pub(crate) struct InferenceTable {
183 189
184impl InferenceTable { 190impl InferenceTable {
185 pub fn new() -> Self { 191 pub fn new() -> Self {
186 InferenceTable { 192 InferenceTable { var_unification_table: InPlaceUnificationTable::new() }
187 var_unification_table: InPlaceUnificationTable::new(),
188 }
189 } 193 }
190 194
191 pub fn new_type_var(&mut self) -> Ty { 195 pub fn new_type_var(&mut self) -> Ty {