mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Do autoderef for indexing
This commit is contained in:
parent
e313efb992
commit
31171eed5e
4 changed files with 74 additions and 7 deletions
|
@ -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>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue