diff options
author | Florian Diebold <[email protected]> | 2019-09-26 20:37:03 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-09-26 22:03:39 +0100 |
commit | daaf46177e5dc63e20e5a1ec5692e53cc8f7bc34 (patch) | |
tree | 2229733948df98f119aee5eca600a50726192c68 /crates/ra_hir/src/ty/infer | |
parent | 1002e470747fe5887a2915689e21d9be3a1ca5d8 (diff) |
Add SubstsBuilder
+ further refactoring.
Diffstat (limited to 'crates/ra_hir/src/ty/infer')
-rw-r--r-- | crates/ra_hir/src/ty/infer/path.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer/unify.rs | 24 |
2 files changed, 14 insertions, 20 deletions
diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs index feb7481b2..db979353a 100644 --- a/crates/ra_hir/src/ty/infer/path.rs +++ b/crates/ra_hir/src/ty/infer/path.rs | |||
@@ -158,13 +158,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
158 | AssocItem::Const(c) => ValueNs::Const(c), | 158 | AssocItem::Const(c) => ValueNs::Const(c), |
159 | AssocItem::TypeAlias(_) => unreachable!(), | 159 | AssocItem::TypeAlias(_) => unreachable!(), |
160 | }; | 160 | }; |
161 | let generics = item.generic_params(self.db); | 161 | let substs = Substs::build_for_def(self.db, item) |
162 | let mut substs = Vec::with_capacity(generics.count_params_including_parent()); | 162 | .use_parent_substs(&trait_ref.substs) |
163 | substs.extend(trait_ref.substs.iter().cloned()); | 163 | .fill_with_unknown() |
164 | substs.extend(std::iter::repeat(Ty::Unknown).take(generics.params.len())); | 164 | .build(); |
165 | 165 | ||
166 | self.write_assoc_resolution(id, item); | 166 | self.write_assoc_resolution(id, item); |
167 | Some((def, Some(substs.into()))) | 167 | Some((def, Some(substs))) |
168 | } | 168 | } |
169 | 169 | ||
170 | fn resolve_ty_assoc_item( | 170 | fn resolve_ty_assoc_item( |
diff --git a/crates/ra_hir/src/ty/infer/unify.rs b/crates/ra_hir/src/ty/infer/unify.rs index b6ebee3b1..d161aa6b3 100644 --- a/crates/ra_hir/src/ty/infer/unify.rs +++ b/crates/ra_hir/src/ty/infer/unify.rs | |||
@@ -3,7 +3,8 @@ | |||
3 | use super::{InferenceContext, Obligation}; | 3 | use super::{InferenceContext, Obligation}; |
4 | use crate::db::HirDatabase; | 4 | use crate::db::HirDatabase; |
5 | use crate::ty::{ | 5 | use crate::ty::{ |
6 | Canonical, InEnvironment, InferTy, ProjectionPredicate, ProjectionTy, TraitRef, Ty, TypeWalk, | 6 | Canonical, InEnvironment, InferTy, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, |
7 | TypeWalk, | ||
7 | }; | 8 | }; |
8 | 9 | ||
9 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 10 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { |
@@ -74,12 +75,9 @@ where | |||
74 | } | 75 | } |
75 | 76 | ||
76 | fn do_canonicalize_trait_ref(&mut self, trait_ref: TraitRef) -> TraitRef { | 77 | fn do_canonicalize_trait_ref(&mut self, trait_ref: TraitRef) -> TraitRef { |
77 | let substs = trait_ref | 78 | let substs = |
78 | .substs | 79 | trait_ref.substs.iter().map(|ty| self.do_canonicalize_ty(ty.clone())).collect(); |
79 | .iter() | 80 | TraitRef { trait_: trait_ref.trait_, substs: Substs(substs) } |
80 | .map(|ty| self.do_canonicalize_ty(ty.clone())) | ||
81 | .collect::<Vec<_>>(); | ||
82 | TraitRef { trait_: trait_ref.trait_, substs: substs.into() } | ||
83 | } | 81 | } |
84 | 82 | ||
85 | fn into_canonicalized<T>(self, result: T) -> Canonicalized<T> { | 83 | fn into_canonicalized<T>(self, result: T) -> Canonicalized<T> { |
@@ -90,12 +88,9 @@ where | |||
90 | } | 88 | } |
91 | 89 | ||
92 | fn do_canonicalize_projection_ty(&mut self, projection_ty: ProjectionTy) -> ProjectionTy { | 90 | fn do_canonicalize_projection_ty(&mut self, projection_ty: ProjectionTy) -> ProjectionTy { |
93 | let params = projection_ty | 91 | let params = |
94 | .parameters | 92 | projection_ty.parameters.iter().map(|ty| self.do_canonicalize_ty(ty.clone())).collect(); |
95 | .iter() | 93 | ProjectionTy { associated_ty: projection_ty.associated_ty, parameters: Substs(params) } |
96 | .map(|ty| self.do_canonicalize_ty(ty.clone())) | ||
97 | .collect::<Vec<_>>(); | ||
98 | ProjectionTy { associated_ty: projection_ty.associated_ty, parameters: params.into() } | ||
99 | } | 94 | } |
100 | 95 | ||
101 | fn do_canonicalize_projection_predicate( | 96 | fn do_canonicalize_projection_predicate( |
@@ -153,8 +148,7 @@ impl<T> Canonicalized<T> { | |||
153 | solution: Canonical<Vec<Ty>>, | 148 | solution: Canonical<Vec<Ty>>, |
154 | ) { | 149 | ) { |
155 | // the solution may contain new variables, which we need to convert to new inference vars | 150 | // the solution may contain new variables, which we need to convert to new inference vars |
156 | let new_vars = | 151 | let new_vars = Substs((0..solution.num_vars).map(|_| ctx.new_type_var()).collect()); |
157 | (0..solution.num_vars).map(|_| ctx.new_type_var()).collect::<Vec<_>>().into(); | ||
158 | for (i, ty) in solution.value.into_iter().enumerate() { | 152 | for (i, ty) in solution.value.into_iter().enumerate() { |
159 | let var = self.free_vars[i]; | 153 | let var = self.free_vars[i]; |
160 | ctx.unify(&Ty::Infer(var), &ty.subst_bound_vars(&new_vars)); | 154 | ctx.unify(&Ty::Infer(var), &ty.subst_bound_vars(&new_vars)); |