aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r--crates/hir_ty/src/infer/expr.rs18
-rw-r--r--crates/hir_ty/src/infer/pat.rs9
-rw-r--r--crates/hir_ty/src/infer/path.rs7
-rw-r--r--crates/hir_ty/src/infer/unify.rs21
4 files changed, 32 insertions, 23 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index ccaae53e9..6966d26e7 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -419,7 +419,7 @@ impl<'a> InferenceContext<'a> {
419 self.result.record_field_resolutions.insert(field.expr, field_def); 419 self.result.record_field_resolutions.insert(field.expr, field_def);
420 } 420 }
421 let field_ty = field_def.map_or(self.err_ty(), |it| { 421 let field_ty = field_def.map_or(self.err_ty(), |it| {
422 field_types[it.local_id].clone().subst(&substs) 422 field_types[it.local_id].clone().substitute(&Interner, &substs)
423 }); 423 });
424 self.infer_expr_coerce(field.expr, &Expectation::has_type(field_ty)); 424 self.infer_expr_coerce(field.expr, &Expectation::has_type(field_ty));
425 } 425 }
@@ -462,7 +462,7 @@ impl<'a> InferenceContext<'a> {
462 Some( 462 Some(
463 self.db.field_types((*s).into())[field.local_id] 463 self.db.field_types((*s).into())[field.local_id]
464 .clone() 464 .clone()
465 .subst(&parameters), 465 .substitute(&Interner, &parameters),
466 ) 466 )
467 } else { 467 } else {
468 None 468 None
@@ -476,7 +476,7 @@ impl<'a> InferenceContext<'a> {
476 Some( 476 Some(
477 self.db.field_types((*u).into())[field.local_id] 477 self.db.field_types((*u).into())[field.local_id]
478 .clone() 478 .clone()
479 .subst(&parameters), 479 .substitute(&Interner, &parameters),
480 ) 480 )
481 } else { 481 } else {
482 None 482 None
@@ -849,10 +849,10 @@ impl<'a> InferenceContext<'a> {
849 self.write_method_resolution(tgt_expr, func); 849 self.write_method_resolution(tgt_expr, func);
850 (ty, self.db.value_ty(func.into()), Some(generics(self.db.upcast(), func.into()))) 850 (ty, self.db.value_ty(func.into()), Some(generics(self.db.upcast(), func.into())))
851 } 851 }
852 None => (receiver_ty, Binders::new(0, self.err_ty()), None), 852 None => (receiver_ty, Binders::empty(&Interner, self.err_ty()), None),
853 }; 853 };
854 let substs = self.substs_for_method_call(def_generics, generic_args, &derefed_receiver_ty); 854 let substs = self.substs_for_method_call(def_generics, generic_args, &derefed_receiver_ty);
855 let method_ty = method_ty.subst(&substs); 855 let method_ty = method_ty.substitute(&Interner, &substs);
856 let method_ty = self.insert_type_vars(method_ty); 856 let method_ty = self.insert_type_vars(method_ty);
857 self.register_obligations_for_call(&method_ty); 857 self.register_obligations_for_call(&method_ty);
858 let (expected_receiver_ty, param_tys, ret_ty) = match method_ty.callable_sig(self.db) { 858 let (expected_receiver_ty, param_tys, ret_ty) = match method_ty.callable_sig(self.db) {
@@ -949,9 +949,11 @@ impl<'a> InferenceContext<'a> {
949 let def: CallableDefId = from_chalk(self.db, *fn_def); 949 let def: CallableDefId = from_chalk(self.db, *fn_def);
950 let generic_predicates = self.db.generic_predicates(def.into()); 950 let generic_predicates = self.db.generic_predicates(def.into());
951 for predicate in generic_predicates.iter() { 951 for predicate in generic_predicates.iter() {
952 let (predicate, binders) = 952 let (predicate, binders) = predicate
953 predicate.clone().subst(parameters).into_value_and_skipped_binders(); 953 .clone()
954 always!(binders == 0); // quantified where clauses not yet handled 954 .substitute(&Interner, parameters)
955 .into_value_and_skipped_binders();
956 always!(binders.len(&Interner) == 0); // quantified where clauses not yet handled
955 self.push_obligation(predicate.cast(&Interner)); 957 self.push_obligation(predicate.cast(&Interner));
956 } 958 }
957 // add obligation for trait implementation, if this is a trait method 959 // add obligation for trait implementation, if this is a trait method
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs
index 469f37dd9..252ae914a 100644
--- a/crates/hir_ty/src/infer/pat.rs
+++ b/crates/hir_ty/src/infer/pat.rs
@@ -49,7 +49,9 @@ impl<'a> InferenceContext<'a> {
49 let expected_ty = var_data 49 let expected_ty = var_data
50 .as_ref() 50 .as_ref()
51 .and_then(|d| d.field(&Name::new_tuple_field(i))) 51 .and_then(|d| d.field(&Name::new_tuple_field(i)))
52 .map_or(self.err_ty(), |field| field_tys[field].clone().subst(&substs)); 52 .map_or(self.err_ty(), |field| {
53 field_tys[field].clone().substitute(&Interner, &substs)
54 });
53 let expected_ty = self.normalize_associated_types_in(expected_ty); 55 let expected_ty = self.normalize_associated_types_in(expected_ty);
54 self.infer_pat(subpat, &expected_ty, default_bm); 56 self.infer_pat(subpat, &expected_ty, default_bm);
55 } 57 }
@@ -83,8 +85,9 @@ impl<'a> InferenceContext<'a> {
83 self.result.record_pat_field_resolutions.insert(subpat.pat, field_def); 85 self.result.record_pat_field_resolutions.insert(subpat.pat, field_def);
84 } 86 }
85 87
86 let expected_ty = matching_field 88 let expected_ty = matching_field.map_or(self.err_ty(), |field| {
87 .map_or(self.err_ty(), |field| field_tys[field].clone().subst(&substs)); 89 field_tys[field].clone().substitute(&Interner, &substs)
90 });
88 let expected_ty = self.normalize_associated_types_in(expected_ty); 91 let expected_ty = self.normalize_associated_types_in(expected_ty);
89 self.infer_pat(subpat.pat, &expected_ty, default_bm); 92 self.infer_pat(subpat.pat, &expected_ty, default_bm);
90 } 93 }
diff --git a/crates/hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs
index 89d78e781..14f705173 100644
--- a/crates/hir_ty/src/infer/path.rs
+++ b/crates/hir_ty/src/infer/path.rs
@@ -81,9 +81,9 @@ impl<'a> InferenceContext<'a> {
81 ValueNs::ImplSelf(impl_id) => { 81 ValueNs::ImplSelf(impl_id) => {
82 let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); 82 let generics = crate::utils::generics(self.db.upcast(), impl_id.into());
83 let substs = generics.type_params_subst(self.db); 83 let substs = generics.type_params_subst(self.db);
84 let ty = self.db.impl_self_ty(impl_id).subst(&substs); 84 let ty = self.db.impl_self_ty(impl_id).substitute(&Interner, &substs);
85 if let Some((AdtId::StructId(struct_id), substs)) = ty.as_adt() { 85 if let Some((AdtId::StructId(struct_id), substs)) = ty.as_adt() {
86 let ty = self.db.value_ty(struct_id.into()).subst(&substs); 86 let ty = self.db.value_ty(struct_id.into()).substitute(&Interner, &substs);
87 return Some(ty); 87 return Some(ty);
88 } else { 88 } else {
89 // FIXME: diagnostic, invalid Self reference 89 // FIXME: diagnostic, invalid Self reference
@@ -243,7 +243,8 @@ impl<'a> InferenceContext<'a> {
243 let impl_substs = TyBuilder::subst_for_def(self.db, impl_id) 243 let impl_substs = TyBuilder::subst_for_def(self.db, impl_id)
244 .fill(iter::repeat_with(|| self.table.new_type_var())) 244 .fill(iter::repeat_with(|| self.table.new_type_var()))
245 .build(); 245 .build();
246 let impl_self_ty = self.db.impl_self_ty(impl_id).subst(&impl_substs); 246 let impl_self_ty =
247 self.db.impl_self_ty(impl_id).substitute(&Interner, &impl_substs);
247 self.unify(&impl_self_ty, &ty); 248 self.unify(&impl_self_ty, &ty);
248 Some(impl_substs) 249 Some(impl_substs)
249 } 250 }
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index 8370f2e1c..c90a16720 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -108,19 +108,22 @@ impl<'a, 'b> Canonicalizer<'a, 'b> {
108} 108}
109 109
110impl<T> Canonicalized<T> { 110impl<T> Canonicalized<T> {
111 pub(super) fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { 111 pub(super) fn decanonicalize_ty(&self, ty: Ty) -> Ty {
112 ty.walk_mut_binders( 112 ty.fold_binders(
113 &mut |ty, binders| { 113 &mut |ty, binders| {
114 if let &mut TyKind::BoundVar(bound) = ty.interned_mut() { 114 if let TyKind::BoundVar(bound) = ty.kind(&Interner) {
115 if bound.debruijn >= binders { 115 if bound.debruijn >= binders {
116 let (v, k) = self.free_vars[bound.index]; 116 let (v, k) = self.free_vars[bound.index];
117 *ty = TyKind::InferenceVar(v, k).intern(&Interner); 117 TyKind::InferenceVar(v, k).intern(&Interner)
118 } else {
119 ty
118 } 120 }
121 } else {
122 ty
119 } 123 }
120 }, 124 },
121 DebruijnIndex::INNERMOST, 125 DebruijnIndex::INNERMOST,
122 ); 126 )
123 ty
124 } 127 }
125 128
126 pub(super) fn apply_solution( 129 pub(super) fn apply_solution(
@@ -149,7 +152,7 @@ impl<T> Canonicalized<T> {
149 // eagerly replace projections in the type; we may be getting types 152 // eagerly replace projections in the type; we may be getting types
150 // e.g. from where clauses where this hasn't happened yet 153 // e.g. from where clauses where this hasn't happened yet
151 let ty = ctx.normalize_associated_types_in( 154 let ty = ctx.normalize_associated_types_in(
152 ty.assert_ty_ref(&Interner).clone().subst_bound_vars(&new_vars), 155 new_vars.apply(ty.assert_ty_ref(&Interner).clone(), &Interner),
153 ); 156 );
154 ctx.table.unify(&TyKind::InferenceVar(v, k).intern(&Interner), &ty); 157 ctx.table.unify(&TyKind::InferenceVar(v, k).intern(&Interner), &ty);
155 } 158 }
@@ -170,8 +173,8 @@ pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option<Substitution> {
170 // fallback to Unknown in the end (kind of hacky, as below) 173 // fallback to Unknown in the end (kind of hacky, as below)
171 .map(|_| table.new_type_var()), 174 .map(|_| table.new_type_var()),
172 ); 175 );
173 let ty1_with_vars = tys.value.0.clone().subst_bound_vars(&vars); 176 let ty1_with_vars = vars.apply(tys.value.0.clone(), &Interner);
174 let ty2_with_vars = tys.value.1.clone().subst_bound_vars(&vars); 177 let ty2_with_vars = vars.apply(tys.value.1.clone(), &Interner);
175 if !table.unify(&ty1_with_vars, &ty2_with_vars) { 178 if !table.unify(&ty1_with_vars, &ty2_with_vars) {
176 return None; 179 return None;
177 } 180 }