aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model.rs15
-rw-r--r--crates/ra_hir/src/ty/lower.rs23
-rw-r--r--crates/ra_hir/src/ty/utils.rs14
3 files changed, 27 insertions, 25 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 50e6409b1..9578c20b0 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -28,8 +28,8 @@ use crate::{
28 expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, 28 expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId},
29 ty::display::HirFormatter, 29 ty::display::HirFormatter,
30 ty::{ 30 ty::{
31 self, utils::all_super_traits, InEnvironment, InferenceResult, Namespace, TraitEnvironment, 31 self, InEnvironment, InferenceResult, Namespace, TraitEnvironment, TraitRef, Ty, TypeCtor,
32 TraitRef, Ty, TypeCtor, TypeWalk, 32 TypeWalk,
33 }, 33 },
34 CallableDef, Either, HirDisplay, Name, Source, 34 CallableDef, Either, HirDisplay, Name, Source,
35}; 35};
@@ -740,17 +740,6 @@ impl Trait {
740 db.trait_data(self.id).items.iter().map(|(_name, it)| (*it).into()).collect() 740 db.trait_data(self.id).items.iter().map(|(_name, it)| (*it).into()).collect()
741 } 741 }
742 742
743 pub fn associated_type_by_name_including_super_traits(
744 self,
745 db: &impl HirDatabase,
746 name: &Name,
747 ) -> Option<TypeAlias> {
748 all_super_traits(db, self.id)
749 .into_iter()
750 .find_map(|t| db.trait_data(t).associated_type_by_name(name))
751 .map(TypeAlias::from)
752 }
753
754 pub fn trait_ref(self, db: &impl HirDatabase) -> TraitRef { 743 pub fn trait_ref(self, db: &impl HirDatabase) -> TraitRef {
755 TraitRef::for_trait(db, self) 744 TraitRef::for_trait(db, self)
756 } 745 }
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 0ac7920bb..805a73ff5 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -28,7 +28,7 @@ use crate::{
28 db::HirDatabase, 28 db::HirDatabase,
29 ty::{ 29 ty::{
30 primitive::{FloatTy, IntTy}, 30 primitive::{FloatTy, IntTy},
31 utils::all_super_traits, 31 utils::{all_super_traits, associated_type_by_name_including_super_traits},
32 Adt, 32 Adt,
33 }, 33 },
34 util::make_mut_slice, 34 util::make_mut_slice,
@@ -170,14 +170,16 @@ impl Ty {
170 ); 170 );
171 return if remaining_segments.len() == 1 { 171 return if remaining_segments.len() == 1 {
172 let segment = &remaining_segments[0]; 172 let segment = &remaining_segments[0];
173 match trait_ref 173 let associated_ty = associated_type_by_name_including_super_traits(
174 .trait_ 174 db,
175 .associated_type_by_name_including_super_traits(db, &segment.name) 175 trait_ref.trait_.id,
176 { 176 &segment.name,
177 );
178 match associated_ty {
177 Some(associated_ty) => { 179 Some(associated_ty) => {
178 // FIXME handle type parameters on the segment 180 // FIXME handle type parameters on the segment
179 Ty::Projection(ProjectionTy { 181 Ty::Projection(ProjectionTy {
180 associated_ty: associated_ty.id, 182 associated_ty,
181 parameters: trait_ref.substs, 183 parameters: trait_ref.substs,
182 }) 184 })
183 } 185 }
@@ -508,10 +510,11 @@ fn assoc_type_bindings_from_type_bound<'a>(
508 .flat_map(|args_and_bindings| args_and_bindings.bindings.iter()) 510 .flat_map(|args_and_bindings| args_and_bindings.bindings.iter())
509 .map(move |(name, type_ref)| { 511 .map(move |(name, type_ref)| {
510 let associated_ty = 512 let associated_ty =
511 match trait_ref.trait_.associated_type_by_name_including_super_traits(db, &name) { 513 associated_type_by_name_including_super_traits(db, trait_ref.trait_.id, &name);
512 None => return GenericPredicate::Error, 514 let associated_ty = match associated_ty {
513 Some(t) => t.id, 515 None => return GenericPredicate::Error,
514 }; 516 Some(t) => t,
517 };
515 let projection_ty = 518 let projection_ty =
516 ProjectionTy { associated_ty, parameters: trait_ref.substs.clone() }; 519 ProjectionTy { associated_ty, parameters: trait_ref.substs.clone() };
517 let ty = Ty::from_hir(db, resolver, type_ref); 520 let ty = Ty::from_hir(db, resolver, type_ref);
diff --git a/crates/ra_hir/src/ty/utils.rs b/crates/ra_hir/src/ty/utils.rs
index 672804787..52994b9e3 100644
--- a/crates/ra_hir/src/ty/utils.rs
+++ b/crates/ra_hir/src/ty/utils.rs
@@ -5,9 +5,9 @@ use hir_def::{
5 db::DefDatabase, 5 db::DefDatabase,
6 resolver::{HasResolver, TypeNs}, 6 resolver::{HasResolver, TypeNs},
7 type_ref::TypeRef, 7 type_ref::TypeRef,
8 TraitId, 8 TraitId, TypeAliasId,
9}; 9};
10use hir_expand::name; 10use hir_expand::name::{self, Name};
11 11
12// FIXME: this is wrong, b/c it can't express `trait T: PartialEq<()>`. 12// FIXME: this is wrong, b/c it can't express `trait T: PartialEq<()>`.
13// We should return a `TraitREf` here. 13// We should return a `TraitREf` here.
@@ -51,3 +51,13 @@ pub(crate) fn all_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec<Tr
51 } 51 }
52 result 52 result
53} 53}
54
55pub(crate) fn associated_type_by_name_including_super_traits(
56 db: &impl DefDatabase,
57 trait_: TraitId,
58 name: &Name,
59) -> Option<TypeAliasId> {
60 all_super_traits(db, trait_)
61 .into_iter()
62 .find_map(|t| db.trait_data(t).associated_type_by_name(name))
63}