mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Remove another helper
This commit is contained in:
parent
25b32f9d68
commit
24b1e79af5
3 changed files with 27 additions and 25 deletions
|
@ -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<TypeAlias> {
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<Tr
|
|||
}
|
||||
result
|
||||
}
|
||||
|
||||
pub(crate) fn associated_type_by_name_including_super_traits(
|
||||
db: &impl DefDatabase,
|
||||
trait_: TraitId,
|
||||
name: &Name,
|
||||
) -> Option<TypeAliasId> {
|
||||
all_super_traits(db, trait_)
|
||||
.into_iter()
|
||||
.find_map(|t| db.trait_data(t).associated_type_by_name(name))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue