aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/infer.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-03 17:18:34 +0100
committerGitHub <[email protected]>2020-07-03 17:18:34 +0100
commit7ad7f3ca8ca7503e3749e93a80ec1b7aa1491e6c (patch)
tree43dbcb044394d4c6c12a183b578abb14b27a5892 /crates/ra_hir_ty/src/infer.rs
parent0f68fed4a0701330e0296f6623567e5584f2f7ba (diff)
parent57feb323f79d1d7f7dd6251d4606ba12a800953a (diff)
Merge #5211
5211: Fix inference of indexing argument (partly) r=flodiebold a=flodiebold We need to add the `T: Index<Arg>` obligation to be resolved later as well, otherwise we can't make inferences about `Arg` later based on the `Index` impls. This still doesn't fix indexing with integer variables though; there's a further problem with Chalk floundering because of the variable, I think. Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/infer.rs')
-rw-r--r--crates/ra_hir_ty/src/infer.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs
index 3719f76a6..5c56c2eb0 100644
--- a/crates/ra_hir_ty/src/infer.rs
+++ b/crates/ra_hir_ty/src/infer.rs
@@ -28,8 +28,8 @@ use hir_def::{
28 path::{path, Path}, 28 path::{path, Path},
29 resolver::{HasResolver, Resolver, TypeNs}, 29 resolver::{HasResolver, Resolver, TypeNs},
30 type_ref::{Mutability, TypeRef}, 30 type_ref::{Mutability, TypeRef},
31 AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, FunctionId, TraitId, TypeAliasId, 31 AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, FunctionId, Lookup, TraitId,
32 VariantId, 32 TypeAliasId, VariantId,
33}; 33};
34use hir_expand::{diagnostics::DiagnosticSink, name::name}; 34use hir_expand::{diagnostics::DiagnosticSink, name::name};
35use ra_arena::map::ArenaMap; 35use ra_arena::map::ArenaMap;
@@ -376,17 +376,21 @@ impl<'a> InferenceContext<'a> {
376 ) -> Ty { 376 ) -> Ty {
377 match assoc_ty { 377 match assoc_ty {
378 Some(res_assoc_ty) => { 378 Some(res_assoc_ty) => {
379 let trait_ = match res_assoc_ty.lookup(self.db.upcast()).container {
380 hir_def::AssocContainerId::TraitId(trait_) => trait_,
381 _ => panic!("resolve_associated_type called with non-associated type"),
382 };
379 let ty = self.table.new_type_var(); 383 let ty = self.table.new_type_var();
380 let builder = Substs::build_for_def(self.db, res_assoc_ty) 384 let substs = Substs::build_for_def(self.db, res_assoc_ty)
381 .push(inner_ty) 385 .push(inner_ty)
382 .fill(params.iter().cloned()); 386 .fill(params.iter().cloned())
387 .build();
388 let trait_ref = TraitRef { trait_, substs: substs.clone() };
383 let projection = ProjectionPredicate { 389 let projection = ProjectionPredicate {
384 ty: ty.clone(), 390 ty: ty.clone(),
385 projection_ty: ProjectionTy { 391 projection_ty: ProjectionTy { associated_ty: res_assoc_ty, parameters: substs },
386 associated_ty: res_assoc_ty,
387 parameters: builder.build(),
388 },
389 }; 392 };
393 self.obligations.push(Obligation::Trait(trait_ref));
390 self.obligations.push(Obligation::Projection(projection)); 394 self.obligations.push(Obligation::Projection(projection));
391 self.resolve_ty_as_possible(ty) 395 self.resolve_ty_as_possible(ty)
392 } 396 }