This commit is contained in:
Aleksey Kladov 2019-11-27 16:48:48 +03:00
parent 12501fcdd0
commit 3686530815

View File

@ -31,7 +31,6 @@
utils::{all_super_traits, associated_type_by_name_including_super_traits, variant_data},
},
util::make_mut_slice,
ImplBlock, Trait,
};
impl Ty {
@ -148,13 +147,8 @@ pub(crate) fn from_partly_resolved_hir_path(
) -> Ty {
let ty = match resolution {
TypeNs::TraitId(trait_) => {
let trait_ref = TraitRef::from_resolved_path(
db,
resolver,
trait_.into(),
resolved_segment,
None,
);
let trait_ref =
TraitRef::from_resolved_path(db, resolver, trait_, resolved_segment, None);
return if remaining_segments.len() == 1 {
let segment = &remaining_segments[0];
let associated_ty = associated_type_by_name_including_super_traits(
@ -187,7 +181,11 @@ pub(crate) fn from_partly_resolved_hir_path(
let name = resolved_segment.name.clone();
Ty::Param { idx, name }
}
TypeNs::SelfType(impl_block) => ImplBlock::from(impl_block).target_ty(db),
TypeNs::SelfType(impl_id) => {
let impl_data = db.impl_data(impl_id);
let resolver = impl_id.resolver(db);
Ty::from_hir(db, &resolver, &impl_data.target_type)
}
TypeNs::AdtSelfType(adt) => db.ty(adt.into()),
TypeNs::AdtId(it) => Ty::from_hir_path_inner(db, resolver, resolved_segment, it.into()),
@ -250,14 +248,11 @@ fn select_associated_type(
GenericPredicate::Implemented(tr) if tr.self_ty() == &self_ty => Some(tr.trait_),
_ => None,
});
let traits = traits_from_env.flat_map(|t| all_super_traits(db, t)).map(Trait::from);
let traits = traits_from_env.flat_map(|t| all_super_traits(db, t));
for t in traits {
if let Some(associated_ty) = db.trait_data(t.id).associated_type_by_name(&segment.name)
{
let substs = Substs::build_for_def(db, t.id)
.push(self_ty.clone())
.fill_with_unknown()
.build();
if let Some(associated_ty) = db.trait_data(t).associated_type_by_name(&segment.name) {
let substs =
Substs::build_for_def(db, t).push(self_ty.clone()).fill_with_unknown().build();
// FIXME handle type parameters on the segment
return Ty::Projection(ProjectionTy { associated_ty, parameters: substs });
}
@ -391,7 +386,7 @@ pub(crate) fn from_path(
pub(super) fn from_resolved_path(
db: &impl HirDatabase,
resolver: &Resolver,
resolved: Trait,
resolved: TraitId,
segment: &PathSegment,
explicit_self_ty: Option<Ty>,
) -> Self {
@ -399,7 +394,7 @@ pub(super) fn from_resolved_path(
if let Some(self_ty) = explicit_self_ty {
make_mut_slice(&mut substs.0)[0] = self_ty;
}
TraitRef { trait_: resolved.id, substs }
TraitRef { trait_: resolved, substs }
}
pub(crate) fn from_hir(
@ -419,11 +414,11 @@ fn substs_from_path(
db: &impl HirDatabase,
resolver: &Resolver,
segment: &PathSegment,
resolved: Trait,
resolved: TraitId,
) -> Substs {
let has_self_param =
segment.args_and_bindings.as_ref().map(|a| a.has_self_type).unwrap_or(false);
substs_from_path_segment(db, resolver, segment, Some(resolved.id.into()), !has_self_param)
substs_from_path_segment(db, resolver, segment, Some(resolved.into()), !has_self_param)
}
pub(crate) fn for_trait(db: &impl HirDatabase, trait_: TraitId) -> TraitRef {