Rename to associated_type_shorthand_candidates

This commit is contained in:
Jonas Schievink 2020-04-30 00:03:36 +02:00
parent 8c2670026a
commit 3cb73da949
3 changed files with 30 additions and 29 deletions

View File

@ -9,7 +9,7 @@ use hir_def::{
AsMacroCall, TraitId,
};
use hir_expand::ExpansionInfo;
use hir_ty::associated_types;
use hir_ty::associated_type_shorthand_candidates;
use itertools::Itertools;
use ra_db::{FileId, FileRange};
use ra_prof::profile;
@ -78,7 +78,7 @@ impl PathResolution {
mut cb: impl FnMut(TypeAlias) -> Option<R>,
) -> Option<R> {
if let Some(res) = self.clone().in_type_ns() {
associated_types(db, res, |_, _, id| cb(id.into()))
associated_type_shorthand_candidates(db, res, |_, _, id| cb(id.into()))
} else {
None
}

View File

@ -66,8 +66,8 @@ pub use autoderef::autoderef;
pub use infer::{InferTy, InferenceResult};
pub use lower::CallableDef;
pub use lower::{
associated_types, callable_item_sig, ImplTraitLoweringMode, TyDefId, TyLoweringContext,
ValueTyDefId,
associated_type_shorthand_candidates, callable_item_sig, ImplTraitLoweringMode, TyDefId,
TyLoweringContext, ValueTyDefId,
};
pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment};

View File

@ -385,31 +385,32 @@ impl Ty {
segment: PathSegment<'_>,
) -> Ty {
if let Some(res) = res {
let ty = associated_types(ctx.db, res, move |name, t, associated_ty| {
if name == segment.name {
let substs = match ctx.type_param_mode {
TypeParamLoweringMode::Placeholder => {
// if we're lowering to placeholders, we have to put
// them in now
let s = Substs::type_params(
ctx.db,
ctx.resolver
.generic_def()
.expect("there should be generics if there's a generic param"),
);
t.substs.clone().subst_bound_vars(&s)
}
TypeParamLoweringMode::Variable => t.substs.clone(),
};
// FIXME handle type parameters on the segment
return Some(Ty::Projection(ProjectionTy {
associated_ty,
parameters: substs,
}));
}
let ty =
associated_type_shorthand_candidates(ctx.db, res, move |name, t, associated_ty| {
if name == segment.name {
let substs = match ctx.type_param_mode {
TypeParamLoweringMode::Placeholder => {
// if we're lowering to placeholders, we have to put
// them in now
let s = Substs::type_params(
ctx.db,
ctx.resolver.generic_def().expect(
"there should be generics if there's a generic param",
),
);
t.substs.clone().subst_bound_vars(&s)
}
TypeParamLoweringMode::Variable => t.substs.clone(),
};
// FIXME handle type parameters on the segment
return Some(Ty::Projection(ProjectionTy {
associated_ty,
parameters: substs,
}));
}
None
});
None
});
ty.unwrap_or(Ty::Unknown)
} else {
@ -671,7 +672,7 @@ pub fn callable_item_sig(db: &dyn HirDatabase, def: CallableDef) -> PolyFnSig {
}
}
pub fn associated_types<R>(
pub fn associated_type_shorthand_candidates<R>(
db: &dyn HirDatabase,
res: TypeNs,
mut cb: impl FnMut(&Name, &TraitRef, TypeAliasId) -> Option<R>,