Skip to content

Commit

Permalink
Auto merge of rust-lang#16705 - regexident:resolve-callable-exprs, r=…
Browse files Browse the repository at this point in the history
…Veykril

Add public function for resolving callable AST exprs to their HIR equivalents

(the PR is motivated by an outside use of the `ra_ap_hir` crate that would benefit from being able to walk a `hir::Function`'s AST, resolving callable exprs within to their HIR equivalents)
  • Loading branch information
bors committed Feb 29, 2024
2 parents a6606d1 + ed34978 commit ecda464
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/hir/src/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,10 @@ impl<'db> SemanticsImpl<'db> {
self.analyze(pat.syntax())?.binding_mode_of_pat(self.db, pat)
}

pub fn resolve_expr_as_callable(&self, call: &ast::Expr) -> Option<Callable> {
self.analyze(call.syntax())?.resolve_expr_as_callable(self.db, call)
}

pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
self.analyze(call.syntax())?.resolve_method_call(self.db, call)
}
Expand Down
8 changes: 8 additions & 0 deletions crates/hir/src/source_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ impl SourceAnalyzer {
}
}

pub(crate) fn resolve_expr_as_callable(
&self,
db: &dyn HirDatabase,
call: &ast::Expr,
) -> Option<Callable> {
self.type_of_expr(db, &call.clone())?.0.as_callable(db)
}

pub(crate) fn resolve_field(
&self,
db: &dyn HirDatabase,
Expand Down

0 comments on commit ecda464

Please sign in to comment.