diff options
| author | bors <bors@rust-lang.org> | 2024-02-29 14:46:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-02-29 14:46:21 +0000 |
| commit | ecda4642efe2315697e49dad4dfc675de11362ee (patch) | |
| tree | 5a193728474dcf40d0bfd159c11ce3aa4e4b9943 | |
| parent | a6606d1767bba67f8ec1a89f9b9c747522b04898 (diff) | |
| parent | ed3497883ca2d6767453fc02cb817b2d56547d95 (diff) | |
| download | rust-ecda4642efe2315697e49dad4dfc675de11362ee.tar.gz rust-ecda4642efe2315697e49dad4dfc675de11362ee.zip | |
Auto merge of #16705 - regexident:resolve-callable-exprs, r=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)
| -rw-r--r-- | crates/hir/src/semantics.rs | 4 | ||||
| -rw-r--r-- | crates/hir/src/source_analyzer.rs | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 1fb6570b6a4..cfda8d4f937 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -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) } diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index 2be47b95149..a147102bcd8 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -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, |
