mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Don't do autoderef for path resolution
This commit is contained in:
parent
1173c3dab5
commit
f4181deb0d
1 changed files with 40 additions and 19 deletions
|
@ -191,6 +191,9 @@ pub(crate) fn iterate_method_candidates<T>(
|
||||||
mode: LookupMode,
|
mode: LookupMode,
|
||||||
mut callback: impl FnMut(&Ty, AssocItem) -> Option<T>,
|
mut callback: impl FnMut(&Ty, AssocItem) -> Option<T>,
|
||||||
) -> Option<T> {
|
) -> Option<T> {
|
||||||
|
let krate = resolver.krate()?;
|
||||||
|
match mode {
|
||||||
|
LookupMode::MethodCall => {
|
||||||
// For method calls, rust first does any number of autoderef, and then one
|
// For method calls, rust first does any number of autoderef, and then one
|
||||||
// autoref (i.e. when the method takes &self or &mut self). We just ignore
|
// autoref (i.e. when the method takes &self or &mut self). We just ignore
|
||||||
// the autoref currently -- when we find a method matching the given name,
|
// the autoref currently -- when we find a method matching the given name,
|
||||||
|
@ -200,19 +203,37 @@ pub(crate) fn iterate_method_candidates<T>(
|
||||||
// find in the end takes &self, we still do the autoderef step (just as
|
// find in the end takes &self, we still do the autoderef step (just as
|
||||||
// rustc does an autoderef and then autoref again).
|
// rustc does an autoderef and then autoref again).
|
||||||
|
|
||||||
let krate = resolver.krate()?;
|
|
||||||
// TODO no autoderef in LookupMode::Path
|
|
||||||
for derefed_ty in autoderef::autoderef(db, resolver, ty.clone()) {
|
for derefed_ty in autoderef::autoderef(db, resolver, ty.clone()) {
|
||||||
if let Some(result) =
|
if let Some(result) =
|
||||||
iterate_inherent_methods(&derefed_ty, db, name, mode, krate, &mut callback)
|
iterate_inherent_methods(&derefed_ty, db, name, mode, krate, &mut callback)
|
||||||
{
|
{
|
||||||
return Some(result);
|
return Some(result);
|
||||||
}
|
}
|
||||||
|
if let Some(result) = iterate_trait_method_candidates(
|
||||||
|
&derefed_ty,
|
||||||
|
db,
|
||||||
|
resolver,
|
||||||
|
name,
|
||||||
|
mode,
|
||||||
|
&mut callback,
|
||||||
|
) {
|
||||||
|
return Some(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LookupMode::Path => {
|
||||||
|
// No autoderef for path lookups
|
||||||
if let Some(result) =
|
if let Some(result) =
|
||||||
iterate_trait_method_candidates(&derefed_ty, db, resolver, name, mode, &mut callback)
|
iterate_inherent_methods(&ty, db, name, mode, krate, &mut callback)
|
||||||
{
|
{
|
||||||
return Some(result);
|
return Some(result);
|
||||||
}
|
}
|
||||||
|
if let Some(result) =
|
||||||
|
iterate_trait_method_candidates(&ty, db, resolver, name, mode, &mut callback)
|
||||||
|
{
|
||||||
|
return Some(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue