(rustc) How to find callee's `DefId` from `hir::Expr`?

Background
I'm writing a custom analysis pass within rustc_driver::Callbacks::after_analysis().

Goal
Given an HirId of a block, I would like to collect DefId of functions that are called inside the block.

Current Status

  • I'm traversing HIR expressions inside the target block and check if ExprKind is Call or MethodCall.
  • rustc_documentation recommends to use qpath_res() for Call(Path(...), ...) and type_dependent_def_id() for MethodCall(...) to get the DefId of the callee. Both methods are defined on TypeckResults.
  • (blocked here) I'm not sure how to get the corresponding TypeckResults for those expressions. I have an access to the global context TyCtxt<'tcx>.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.