From dddee23f43a0e1939124a607ba534e69a810843a Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 19 Dec 2019 12:45:07 +0800 Subject: Add std::ops::Index support for infering --- crates/ra_hir_ty/src/infer.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_ty/src/infer.rs') diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index 98ba05fc2..14bfdde3d 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs @@ -363,14 +363,28 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } fn resolve_associated_type(&mut self, inner_ty: Ty, assoc_ty: Option) -> Ty { + self.resolve_associated_type_with_params(inner_ty, assoc_ty, &[]) + } + + fn resolve_associated_type_with_params( + &mut self, + inner_ty: Ty, + assoc_ty: Option, + params: &[Ty], + ) -> Ty { match assoc_ty { Some(res_assoc_ty) => { let ty = self.table.new_type_var(); + let mut builder = Substs::builder(1 + params.len()).push(inner_ty); + for ty in params { + builder = builder.push(ty.clone()); + } + let projection = ProjectionPredicate { ty: ty.clone(), projection_ty: ProjectionTy { associated_ty: res_assoc_ty, - parameters: Substs::single(inner_ty), + parameters: builder.build(), }, }; self.obligations.push(Obligation::Projection(projection)); @@ -517,6 +531,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; Some(struct_.into()) } + + fn resolve_ops_index_output(&self) -> Option { + let path = path![std::ops::Index]; + let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; + self.db.trait_data(trait_).associated_type_by_name(&name![Output]) + } } /// The kinds of placeholders we need during type inference. There's separate -- cgit v1.2.3 From b61ad6a96430f82e9724c1831d7402705145750e Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 19 Dec 2019 22:28:52 +0800 Subject: Use build_for_def --- crates/ra_hir_ty/src/infer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_hir_ty/src/infer.rs') diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index 14bfdde3d..98baeed6f 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs @@ -375,7 +375,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { match assoc_ty { Some(res_assoc_ty) => { let ty = self.table.new_type_var(); - let mut builder = Substs::builder(1 + params.len()).push(inner_ty); + let mut builder = Substs::build_for_def(self.db, res_assoc_ty).push(inner_ty); for ty in params { builder = builder.push(ty.clone()); } -- cgit v1.2.3 From 76d688a328ab53b6264f9e489b88524377a7271d Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 20 Dec 2019 03:04:55 +0800 Subject: Use fill instread of for loop --- crates/ra_hir_ty/src/infer.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir_ty/src/infer.rs') diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index 98baeed6f..bbbc391c4 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs @@ -375,11 +375,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { match assoc_ty { Some(res_assoc_ty) => { let ty = self.table.new_type_var(); - let mut builder = Substs::build_for_def(self.db, res_assoc_ty).push(inner_ty); - for ty in params { - builder = builder.push(ty.clone()); - } - + let builder = Substs::build_for_def(self.db, res_assoc_ty) + .push(inner_ty) + .fill(params.iter().cloned()); let projection = ProjectionPredicate { ty: ty.clone(), projection_ty: ProjectionTy { -- cgit v1.2.3