Skip to content

Commit 24b1e79

Browse files
committed
Remove another helper
1 parent 25b32f9 commit 24b1e79

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

crates/ra_hir/src/code_model.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use crate::{
2828
expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId},
2929
ty::display::HirFormatter,
3030
ty::{
31-
self, utils::all_super_traits, InEnvironment, InferenceResult, Namespace, TraitEnvironment,
32-
TraitRef, Ty, TypeCtor, TypeWalk,
31+
self, InEnvironment, InferenceResult, Namespace, TraitEnvironment, TraitRef, Ty, TypeCtor,
32+
TypeWalk,
3333
},
3434
CallableDef, Either, HirDisplay, Name, Source,
3535
};
@@ -740,17 +740,6 @@ impl Trait {
740740
db.trait_data(self.id).items.iter().map(|(_name, it)| (*it).into()).collect()
741741
}
742742

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-
754743
pub fn trait_ref(self, db: &impl HirDatabase) -> TraitRef {
755744
TraitRef::for_trait(db, self)
756745
}

crates/ra_hir/src/ty/lower.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::{
2828
db::HirDatabase,
2929
ty::{
3030
primitive::{FloatTy, IntTy},
31-
utils::all_super_traits,
31+
utils::{all_super_traits, associated_type_by_name_including_super_traits},
3232
Adt,
3333
},
3434
util::make_mut_slice,
@@ -170,14 +170,16 @@ impl Ty {
170170
);
171171
return if remaining_segments.len() == 1 {
172172
let segment = &remaining_segments[0];
173-
match trait_ref
174-
.trait_
175-
.associated_type_by_name_including_super_traits(db, &segment.name)
176-
{
173+
let associated_ty = associated_type_by_name_including_super_traits(
174+
db,
175+
trait_ref.trait_.id,
176+
&segment.name,
177+
);
178+
match associated_ty {
177179
Some(associated_ty) => {
178180
// FIXME handle type parameters on the segment
179181
Ty::Projection(ProjectionTy {
180-
associated_ty: associated_ty.id,
182+
associated_ty,
181183
parameters: trait_ref.substs,
182184
})
183185
}
@@ -508,10 +510,11 @@ fn assoc_type_bindings_from_type_bound<'a>(
508510
.flat_map(|args_and_bindings| args_and_bindings.bindings.iter())
509511
.map(move |(name, type_ref)| {
510512
let associated_ty =
511-
match trait_ref.trait_.associated_type_by_name_including_super_traits(db, &name) {
512-
None => return GenericPredicate::Error,
513-
Some(t) => t.id,
514-
};
513+
associated_type_by_name_including_super_traits(db, trait_ref.trait_.id, &name);
514+
let associated_ty = match associated_ty {
515+
None => return GenericPredicate::Error,
516+
Some(t) => t,
517+
};
515518
let projection_ty =
516519
ProjectionTy { associated_ty, parameters: trait_ref.substs.clone() };
517520
let ty = Ty::from_hir(db, resolver, type_ref);

crates/ra_hir/src/ty/utils.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use hir_def::{
55
db::DefDatabase,
66
resolver::{HasResolver, TypeNs},
77
type_ref::TypeRef,
8-
TraitId,
8+
TraitId, TypeAliasId,
99
};
10-
use hir_expand::name;
10+
use hir_expand::name::{self, Name};
1111

1212
// FIXME: this is wrong, b/c it can't express `trait T: PartialEq<()>`.
1313
// We should return a `TraitREf` here.
@@ -51,3 +51,13 @@ pub(crate) fn all_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec<Tr
5151
}
5252
result
5353
}
54+
55+
pub(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+
}

0 commit comments

Comments
 (0)