aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-08-07 21:06:09 +0100
committerFlorian Diebold <[email protected]>2019-08-12 20:43:00 +0100
commit6265497523469990ce39e6817423c35a17055a54 (patch)
treee50d81f36127412fa4238d2a71637358bc2d1b5f /crates
parent22724f37f3ae73983bf700d10d80a8dbd4fa4073 (diff)
Normalize associated types during inference
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/ty/infer.rs22
-rw-r--r--crates/ra_hir/src/ty/lower.rs5
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs7
3 files changed, 25 insertions, 9 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 594c5bc79..74fc77cfb 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -245,7 +245,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
245 &self.resolver, 245 &self.resolver,
246 type_ref, 246 type_ref,
247 ); 247 );
248 self.insert_type_vars(ty) 248 let ty = self.insert_type_vars(ty);
249 self.normalize_associated_types_in(ty)
249 } 250 }
250 251
251 fn unify_substs(&mut self, substs1: &Substs, substs2: &Substs, depth: usize) -> bool { 252 fn unify_substs(&mut self, substs1: &Substs, substs2: &Substs, depth: usize) -> bool {
@@ -411,6 +412,25 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
411 ty 412 ty
412 } 413 }
413 414
415 fn normalize_associated_types_in(&mut self, ty: Ty) -> Ty {
416 ty.fold(&mut |ty| match ty {
417 Ty::Projection(proj_ty) => self.normalize_projection_ty(proj_ty),
418 Ty::UnselectedProjection(proj_ty) => {
419 // FIXME
420 Ty::UnselectedProjection(proj_ty)
421 }
422 _ => ty,
423 })
424 }
425
426 fn normalize_projection_ty(&mut self, proj_ty: ProjectionTy) -> Ty {
427 let var = self.new_type_var();
428 let predicate = ProjectionPredicate { projection_ty: proj_ty.clone(), ty: var.clone() };
429 let obligation = Obligation::Projection(predicate);
430 self.obligations.push(obligation);
431 var
432 }
433
414 /// Resolves the type completely; type variables without known type are 434 /// Resolves the type completely; type variables without known type are
415 /// replaced by Ty::Unknown. 435 /// replaced by Ty::Unknown.
416 fn resolve_ty_completely(&mut self, tv_stack: &mut Vec<TypeVarId>, ty: Ty) -> Ty { 436 fn resolve_ty_completely(&mut self, tv_stack: &mut Vec<TypeVarId>, ty: Ty) -> Ty {
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 24ec77fcf..debedcbb8 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -117,11 +117,6 @@ impl Ty {
117 return Ty::Unknown; 117 return Ty::Unknown;
118 } 118 }
119 }; 119 };
120 eprintln!(
121 "assoc ty: {:?}, parameters: {:?}",
122 associated_ty.name(db),
123 trait_ref.substs
124 );
125 // FIXME handle type parameters on the segment 120 // FIXME handle type parameters on the segment
126 Ty::Projection(ProjectionTy { associated_ty, parameters: trait_ref.substs }) 121 Ty::Projection(ProjectionTy { associated_ty, parameters: trait_ref.substs })
127 } else { 122 } else {
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs
index 21055dcfd..e669f835b 100644
--- a/crates/ra_hir/src/ty/traits/chalk.rs
+++ b/crates/ra_hir/src/ty/traits/chalk.rs
@@ -402,11 +402,12 @@ where
402 &self, 402 &self,
403 projection: &'p chalk_ir::ProjectionTy, 403 projection: &'p chalk_ir::ProjectionTy,
404 ) -> (Arc<AssociatedTyDatum>, &'p [Parameter], &'p [Parameter]) { 404 ) -> (Arc<AssociatedTyDatum>, &'p [Parameter], &'p [Parameter]) {
405 debug!("split_projection {:?}", projection); 405 let proj_ty: ProjectionTy = from_chalk(self.db, projection.clone());
406 unimplemented!() 406 debug!("split_projection {:?} = {}", projection, proj_ty.display(self.db));
407 // we don't support GATs, so I think this should always be correct currently
408 (self.db.associated_ty_data(projection.associated_ty_id), &projection.parameters, &[])
407 } 409 }
408 fn custom_clauses(&self) -> Vec<chalk_ir::ProgramClause> { 410 fn custom_clauses(&self) -> Vec<chalk_ir::ProgramClause> {
409 debug!("custom_clauses");
410 vec![] 411 vec![]
411 } 412 }
412 fn all_structs(&self) -> Vec<chalk_ir::StructId> { 413 fn all_structs(&self) -> Vec<chalk_ir::StructId> {