From 24b1e79af51f5af76047a5eee2fe90baf100afca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 26 Nov 2019 17:42:21 +0300 Subject: Remove another helper --- crates/ra_hir/src/code_model.rs | 15 ++------------- crates/ra_hir/src/ty/lower.rs | 23 +++++++++++++---------- crates/ra_hir/src/ty/utils.rs | 14 ++++++++++++-- 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::{ expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, ty::display::HirFormatter, ty::{ - self, utils::all_super_traits, InEnvironment, InferenceResult, Namespace, TraitEnvironment, - TraitRef, Ty, TypeCtor, TypeWalk, + self, InEnvironment, InferenceResult, Namespace, TraitEnvironment, TraitRef, Ty, TypeCtor, + TypeWalk, }, CallableDef, Either, HirDisplay, Name, Source, }; @@ -740,17 +740,6 @@ impl Trait { db.trait_data(self.id).items.iter().map(|(_name, it)| (*it).into()).collect() } - pub fn associated_type_by_name_including_super_traits( - self, - db: &impl HirDatabase, - name: &Name, - ) -> Option { - all_super_traits(db, self.id) - .into_iter() - .find_map(|t| db.trait_data(t).associated_type_by_name(name)) - .map(TypeAlias::from) - } - pub fn trait_ref(self, db: &impl HirDatabase) -> TraitRef { TraitRef::for_trait(db, self) } 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::{ db::HirDatabase, ty::{ primitive::{FloatTy, IntTy}, - utils::all_super_traits, + utils::{all_super_traits, associated_type_by_name_including_super_traits}, Adt, }, util::make_mut_slice, @@ -170,14 +170,16 @@ impl Ty { ); return if remaining_segments.len() == 1 { let segment = &remaining_segments[0]; - match trait_ref - .trait_ - .associated_type_by_name_including_super_traits(db, &segment.name) - { + let associated_ty = associated_type_by_name_including_super_traits( + db, + trait_ref.trait_.id, + &segment.name, + ); + match associated_ty { Some(associated_ty) => { // FIXME handle type parameters on the segment Ty::Projection(ProjectionTy { - associated_ty: associated_ty.id, + associated_ty, parameters: trait_ref.substs, }) } @@ -508,10 +510,11 @@ fn assoc_type_bindings_from_type_bound<'a>( .flat_map(|args_and_bindings| args_and_bindings.bindings.iter()) .map(move |(name, type_ref)| { let associated_ty = - match trait_ref.trait_.associated_type_by_name_including_super_traits(db, &name) { - None => return GenericPredicate::Error, - Some(t) => t.id, - }; + associated_type_by_name_including_super_traits(db, trait_ref.trait_.id, &name); + let associated_ty = match associated_ty { + None => return GenericPredicate::Error, + Some(t) => t, + }; let projection_ty = ProjectionTy { associated_ty, parameters: trait_ref.substs.clone() }; 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::{ db::DefDatabase, resolver::{HasResolver, TypeNs}, type_ref::TypeRef, - TraitId, + TraitId, TypeAliasId, }; -use hir_expand::name; +use hir_expand::name::{self, Name}; // FIXME: this is wrong, b/c it can't express `trait T: PartialEq<()>`. // We should return a `TraitREf` here. @@ -51,3 +51,13 @@ pub(crate) fn all_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec Option { + all_super_traits(db, trait_) + .into_iter() + .find_map(|t| db.trait_data(t).associated_type_by_name(name)) +} -- cgit v1.2.3