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

@ -12,7 +12,7 @@ use hir_def::{
macro_id_to_def_id,
resolver::{self, HasResolver, Resolver, TypeNs},
type_ref::Mutability,
AsMacroCall, DefWithBodyId, FunctionId, MacroId, TraitId, VariantId,
AsMacroCall, DefWithBodyId, FieldId, FunctionId, MacroId, TraitId, VariantId,
};
use hir_expand::{
db::AstDatabase,
@ -366,6 +366,16 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
self.imp.resolve_method_call(call).map(Function::from)
}
/// Attempts to resolve this call expression as a method call falling back to resolving it as a field.
pub fn resolve_method_call_field_fallback(
&self,
call: &ast::MethodCallExpr,
) -> Option<Either<Function, Field>> {
self.imp
.resolve_method_call_fallback(call)
.map(|it| it.map_left(Function::from).map_right(Field::from))
}
pub fn resolve_await_to_poll(&self, await_expr: &ast::AwaitExpr) -> Option<Function> {
self.imp.resolve_await_to_poll(await_expr).map(Function::from)
}
@ -1146,6 +1156,13 @@ impl<'db> SemanticsImpl<'db> {
self.analyze(call.syntax())?.resolve_method_call(self.db, call)
}
fn resolve_method_call_fallback(
&self,
call: &ast::MethodCallExpr,
) -> Option<Either<FunctionId, FieldId>> {
self.analyze(call.syntax())?.resolve_method_call_fallback(self.db, call)
}
fn resolve_await_to_poll(&self, await_expr: &ast::AwaitExpr) -> Option<FunctionId> {
self.analyze(await_expr.syntax())?.resolve_await_to_poll(self.db, await_expr)
}