Skip to content

Commit 5ddc4f2

Browse files
committed
coverage: Inline creating a dummy instance for unused functions
1 parent 5f2c7d2 commit 5ddc4f2

File tree

1 file changed

+11
-11
lines changed
  • compiler/rustc_codegen_llvm/src/coverageinfo

1 file changed

+11
-11
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,7 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {
385385
};
386386

387387
debug!("generating unused fn: {def_id:?}");
388-
let instance = declare_unused_fn(tcx, def_id);
389-
add_unused_function_coverage(cx, instance, function_coverage_info);
388+
add_unused_function_coverage(cx, def_id, function_coverage_info);
390389
}
391390
}
392391

@@ -421,8 +420,15 @@ fn codegenned_and_inlined_items(tcx: TyCtxt<'_>) -> DefIdSet {
421420
result
422421
}
423422

424-
fn declare_unused_fn<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::Instance<'tcx> {
425-
ty::Instance::new(
423+
fn add_unused_function_coverage<'tcx>(
424+
cx: &CodegenCx<'_, 'tcx>,
425+
def_id: DefId,
426+
function_coverage_info: &'tcx mir::coverage::FunctionCoverageInfo,
427+
) {
428+
let tcx = cx.tcx;
429+
430+
// Make a dummy instance that fills in all generics with placeholders.
431+
let instance = ty::Instance::new(
426432
def_id,
427433
ty::GenericArgs::for_item(tcx, def_id, |param, _| {
428434
if let ty::GenericParamDefKind::Lifetime = param.kind {
@@ -431,14 +437,8 @@ fn declare_unused_fn<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::Instance<'tc
431437
tcx.mk_param_from_def(param)
432438
}
433439
}),
434-
)
435-
}
440+
);
436441

437-
fn add_unused_function_coverage<'tcx>(
438-
cx: &CodegenCx<'_, 'tcx>,
439-
instance: ty::Instance<'tcx>,
440-
function_coverage_info: &'tcx mir::coverage::FunctionCoverageInfo,
441-
) {
442442
// An unused function's mappings will automatically be rewritten to map to
443443
// zero, because none of its counters/expressions are marked as seen.
444444
let function_coverage = FunctionCoverageCollector::unused(instance, function_coverage_info);

0 commit comments

Comments
 (0)