internal: Handle fields called as method calls as the fields they resolve to

This commit is contained in:
Lukas Wirth 2023-03-04 20:33:28 +01:00
parent b85e2af898
commit 5a91f015b4
4 changed files with 63 additions and 4 deletions

View file

@ -10,6 +10,7 @@ use std::{
sync::Arc,
};
use either::Either;
use hir_def::{
body::{
self,
@ -266,6 +267,21 @@ impl SourceAnalyzer {
Some(self.resolve_impl_method_or_trait_def(db, f_in_trait, substs))
}
pub(crate) fn resolve_method_call_fallback(
&self,
db: &dyn HirDatabase,
call: &ast::MethodCallExpr,
) -> Option<Either<FunctionId, FieldId>> {
let expr_id = self.expr_id(db, &call.clone().into())?;
let inference_result = self.infer.as_ref()?;
match inference_result.method_resolution(expr_id) {
Some((f_in_trait, substs)) => {
Some(Either::Left(self.resolve_impl_method_or_trait_def(db, f_in_trait, substs)))
}
None => inference_result.field_resolution(expr_id).map(Either::Right),
}
}
pub(crate) fn resolve_await_to_poll(
&self,
db: &dyn HirDatabase,