Resolve direct call. Inspired by rustc_mir/src/transform/inline.rs#get_valid_function_call.
(&mut self, terminator: &Terminator<'tcx>, location: Location)
| 199 | |
| 200 | impl<'tcx> Visitor<'tcx> for CallSiteCollector<'_, 'tcx> { |
| 201 | /// Resolve direct call. |
| 202 | /// Inspired by rustc_mir/src/transform/inline.rs#get_valid_function_call. |
| 203 | fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) { |
| 204 | if let TerminatorKind::Call { ref func, .. } = terminator.kind { |
| 205 | let func_ty = func.ty(self.body, self.tcx); |
| 206 | // Only after monomorphizing can Instance::try_resolve work |
| 207 | let func_ty = self.caller.instantiate_mir_and_normalize_erasing_regions( |
| 208 | self.tcx, |
| 209 | self.typing_env, |
| 210 | EarlyBinder::bind(func_ty), |
| 211 | ); |
| 212 | if let ty::FnDef(def_id, substs) = *func_ty.kind() { |
| 213 | if let Some(callee) = |
| 214 | Instance::try_resolve(self.tcx, self.typing_env, def_id, substs) |
| 215 | .ok() |
| 216 | .flatten() |
| 217 | { |
| 218 | self.callsites |
| 219 | .push((callee, CallSiteLocation::Direct(location))); |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | self.super_terminator(terminator, location); |
| 224 | } |
| 225 |
nothing calls this directly
no outgoing calls
no test coverage detected