Do autoderef for indexing

This commit is contained in:
Florian Diebold 2020-02-29 22:48:23 +01:00
parent e313efb992
commit 31171eed5e
4 changed files with 74 additions and 7 deletions

View file

@ -447,6 +447,25 @@ fn iterate_inherent_methods<T>(
None
}
/// Returns the self type for the index trait call.
pub fn resolve_indexing_op(
db: &impl HirDatabase,
ty: &Canonical<Ty>,
env: Arc<TraitEnvironment>,
krate: CrateId,
index_trait: TraitId,
) -> Option<Canonical<Ty>> {
let ty = InEnvironment { value: ty.clone(), environment: env.clone() };
let deref_chain = autoderef_method_receiver(db, krate, ty);
for ty in deref_chain {
let goal = generic_implements_goal(db, env.clone(), index_trait, ty.clone());
if db.trait_solve(krate, goal).is_some() {
return Some(ty);
}
}
None
}
fn is_valid_candidate(
db: &impl HirDatabase,
name: Option<&Name>,