mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +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},
|
expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId},
|
||||||
ty::display::HirFormatter,
|
ty::display::HirFormatter,
|
||||||
ty::{
|
ty::{
|
||||||
self, utils::all_super_traits, InEnvironment, InferenceResult, Namespace, TraitEnvironment,
|
self, InEnvironment, InferenceResult, Namespace, TraitEnvironment, TraitRef, Ty, TypeCtor,
|
||||||
TraitRef, Ty, TypeCtor, TypeWalk,
|
TypeWalk,
|
||||||
},
|
},
|
||||||
CallableDef, Either, HirDisplay, Name, Source,
|
CallableDef, Either, HirDisplay, Name, Source,
|
||||||
};
|
};
|
||||||
|
@ -740,17 +740,6 @@ impl Trait {
|
||||||
db.trait_data(self.id).items.iter().map(|(_name, it)| (*it).into()).collect()
|
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 {
|
pub fn trait_ref(self, db: &impl HirDatabase) -> TraitRef {
|
||||||
TraitRef::for_trait(db, self)
|
TraitRef::for_trait(db, self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
ty::{
|
ty::{
|
||||||
primitive::{FloatTy, IntTy},
|
primitive::{FloatTy, IntTy},
|
||||||
utils::all_super_traits,
|
utils::{all_super_traits, associated_type_by_name_including_super_traits},
|
||||||
Adt,
|
Adt,
|
||||||
},
|
},
|
||||||
util::make_mut_slice,
|
util::make_mut_slice,
|
||||||
|
@ -170,14 +170,16 @@ impl Ty {
|
||||||
);
|
);
|
||||||
return if remaining_segments.len() == 1 {
|
return if remaining_segments.len() == 1 {
|
||||||
let segment = &remaining_segments[0];
|
let segment = &remaining_segments[0];
|
||||||
match trait_ref
|
let associated_ty = associated_type_by_name_including_super_traits(
|
||||||
.trait_
|
db,
|
||||||
.associated_type_by_name_including_super_traits(db, &segment.name)
|
trait_ref.trait_.id,
|
||||||
{
|
&segment.name,
|
||||||
|
);
|
||||||
|
match associated_ty {
|
||||||
Some(associated_ty) => {
|
Some(associated_ty) => {
|
||||||
// FIXME handle type parameters on the segment
|
// FIXME handle type parameters on the segment
|
||||||
Ty::Projection(ProjectionTy {
|
Ty::Projection(ProjectionTy {
|
||||||
associated_ty: associated_ty.id,
|
associated_ty,
|
||||||
parameters: trait_ref.substs,
|
parameters: trait_ref.substs,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -508,9 +510,10 @@ fn assoc_type_bindings_from_type_bound<'a>(
|
||||||
.flat_map(|args_and_bindings| args_and_bindings.bindings.iter())
|
.flat_map(|args_and_bindings| args_and_bindings.bindings.iter())
|
||||||
.map(move |(name, type_ref)| {
|
.map(move |(name, type_ref)| {
|
||||||
let associated_ty =
|
let associated_ty =
|
||||||
match trait_ref.trait_.associated_type_by_name_including_super_traits(db, &name) {
|
associated_type_by_name_including_super_traits(db, trait_ref.trait_.id, &name);
|
||||||
|
let associated_ty = match associated_ty {
|
||||||
None => return GenericPredicate::Error,
|
None => return GenericPredicate::Error,
|
||||||
Some(t) => t.id,
|
Some(t) => t,
|
||||||
};
|
};
|
||||||
let projection_ty =
|
let projection_ty =
|
||||||
ProjectionTy { associated_ty, parameters: trait_ref.substs.clone() };
|
ProjectionTy { associated_ty, parameters: trait_ref.substs.clone() };
|
||||||
|
|
|
@ -5,9 +5,9 @@ use hir_def::{
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
resolver::{HasResolver, TypeNs},
|
resolver::{HasResolver, TypeNs},
|
||||||
type_ref::TypeRef,
|
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<()>`.
|
// FIXME: this is wrong, b/c it can't express `trait T: PartialEq<()>`.
|
||||||
// We should return a `TraitREf` here.
|
// We should return a `TraitREf` here.
|
||||||
|
@ -51,3 +51,13 @@ pub(crate) fn all_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec<Tr
|
||||||
}
|
}
|
||||||
result
|
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…
Add table
Add a link
Reference in a new issue