aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/infer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/infer.rs')
-rw-r--r--crates/ra_hir_ty/src/infer.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs
index 377f44fa7..39f144216 100644
--- a/crates/ra_hir_ty/src/infer.rs
+++ b/crates/ra_hir_ty/src/infer.rs
@@ -425,7 +425,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
425 let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); 425 let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver);
426 // FIXME: this should resolve assoc items as well, see this example: 426 // FIXME: this should resolve assoc items as well, see this example:
427 // https://play.rust-lang.org/?gist=087992e9e22495446c01c0d4e2d69521 427 // https://play.rust-lang.org/?gist=087992e9e22495446c01c0d4e2d69521
428 match resolver.resolve_path_in_type_ns_fully(self.db, path.mod_path()) { 428 return match resolver.resolve_path_in_type_ns_fully(self.db, path.mod_path()) {
429 Some(TypeNs::AdtId(AdtId::StructId(strukt))) => { 429 Some(TypeNs::AdtId(AdtId::StructId(strukt))) => {
430 let substs = Ty::substs_from_path(&ctx, path, strukt.into()); 430 let substs = Ty::substs_from_path(&ctx, path, strukt.into());
431 let ty = self.db.ty(strukt.into()); 431 let ty = self.db.ty(strukt.into());
@@ -438,7 +438,33 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
438 let ty = self.insert_type_vars(ty.subst(&substs)); 438 let ty = self.insert_type_vars(ty.subst(&substs));
439 (ty, Some(var.into())) 439 (ty, Some(var.into()))
440 } 440 }
441 Some(TypeNs::SelfType(impl_id)) => {
442 let generics = crate::utils::generics(self.db, impl_id.into());
443 let substs = Substs::type_params_for_generics(&generics);
444 let ty = self.db.impl_self_ty(impl_id).subst(&substs);
445 let variant = ty_variant(&ty);
446 (ty, variant)
447 }
448 Some(TypeNs::TypeAliasId(it)) => {
449 let substs = Substs::build_for_def(self.db, it)
450 .fill(std::iter::repeat_with(|| self.table.new_type_var()))
451 .build();
452 let ty = self.db.ty(it.into()).subst(&substs);
453 let variant = ty_variant(&ty);
454 (ty, variant)
455 }
441 Some(_) | None => (Ty::Unknown, None), 456 Some(_) | None => (Ty::Unknown, None),
457 };
458
459 fn ty_variant(ty: &Ty) -> Option<VariantId> {
460 ty.as_adt().and_then(|(adt_id, _)| match adt_id {
461 AdtId::StructId(s) => Some(VariantId::StructId(s)),
462 AdtId::UnionId(u) => Some(VariantId::UnionId(u)),
463 AdtId::EnumId(_) => {
464 // Error E0071, expected struct, variant or union type, found enum `Foo`
465 None
466 }
467 })
442 } 468 }
443 } 469 }
444 470