aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/infer.rs
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-12-19 04:45:07 +0000
committerEdwin Cheng <[email protected]>2019-12-19 04:45:07 +0000
commitdddee23f43a0e1939124a607ba534e69a810843a (patch)
tree02fd55e52fcd54b43f218303b9a9fc2fd7d623b0 /crates/ra_hir_ty/src/infer.rs
parent242f0ae1d8e6766091a6050431c3d417a43a2a3e (diff)
Add std::ops::Index support for infering
Diffstat (limited to 'crates/ra_hir_ty/src/infer.rs')
-rw-r--r--crates/ra_hir_ty/src/infer.rs22
1 files changed, 21 insertions, 1 deletions
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> {
363 } 363 }
364 364
365 fn resolve_associated_type(&mut self, inner_ty: Ty, assoc_ty: Option<TypeAliasId>) -> Ty { 365 fn resolve_associated_type(&mut self, inner_ty: Ty, assoc_ty: Option<TypeAliasId>) -> Ty {
366 self.resolve_associated_type_with_params(inner_ty, assoc_ty, &[])
367 }
368
369 fn resolve_associated_type_with_params(
370 &mut self,
371 inner_ty: Ty,
372 assoc_ty: Option<TypeAliasId>,
373 params: &[Ty],
374 ) -> Ty {
366 match assoc_ty { 375 match assoc_ty {
367 Some(res_assoc_ty) => { 376 Some(res_assoc_ty) => {
368 let ty = self.table.new_type_var(); 377 let ty = self.table.new_type_var();
378 let mut builder = Substs::builder(1 + params.len()).push(inner_ty);
379 for ty in params {
380 builder = builder.push(ty.clone());
381 }
382
369 let projection = ProjectionPredicate { 383 let projection = ProjectionPredicate {
370 ty: ty.clone(), 384 ty: ty.clone(),
371 projection_ty: ProjectionTy { 385 projection_ty: ProjectionTy {
372 associated_ty: res_assoc_ty, 386 associated_ty: res_assoc_ty,
373 parameters: Substs::single(inner_ty), 387 parameters: builder.build(),
374 }, 388 },
375 }; 389 };
376 self.obligations.push(Obligation::Projection(projection)); 390 self.obligations.push(Obligation::Projection(projection));
@@ -517,6 +531,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
517 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; 531 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?;
518 Some(struct_.into()) 532 Some(struct_.into())
519 } 533 }
534
535 fn resolve_ops_index_output(&self) -> Option<TypeAliasId> {
536 let path = path![std::ops::Index];
537 let trait_ = self.resolver.resolve_known_trait(self.db, &path)?;
538 self.db.trait_data(trait_).associated_type_by_name(&name![Output])
539 }
520} 540}
521 541
522/// The kinds of placeholders we need during type inference. There's separate 542/// The kinds of placeholders we need during type inference. There's separate