Skip to content

Commit 315c0cf

Browse files
committed
coverage: Simplify parts of InstrumentCoverage::run_pass
Changes in this patch: - Extract local variable `def_id` - Check `is_fn_like` without retrieving HIR - Inline some locals that are used once and aren't needed for clarity
1 parent 87cffb2 commit 315c0cf

File tree

1 file changed

+6
-8
lines changed
  • compiler/rustc_mir_transform/src/coverage

1 file changed

+6
-8
lines changed

compiler/rustc_mir_transform/src/coverage/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ impl<'tcx> MirPass<'tcx> for InstrumentCoverage {
4343
// be transformed, so it should never see promoted MIR.
4444
assert!(mir_source.promoted.is_none());
4545

46-
let is_fn_like =
47-
tcx.hir_node_by_def_id(mir_source.def_id().expect_local()).fn_kind().is_some();
46+
let def_id = mir_source.def_id().expect_local();
4847

4948
// Only instrument functions, methods, and closures (not constants since they are evaluated
5049
// at compile time by Miri).
@@ -53,8 +52,8 @@ impl<'tcx> MirPass<'tcx> for InstrumentCoverage {
5352
// expressions from coverage spans in enclosing MIR's, like we do for closures. (That might
5453
// be tricky if const expressions have no corresponding statements in the enclosing MIR.
5554
// Closures are carved out by their initial `Assign` statement.)
56-
if !is_fn_like {
57-
trace!("InstrumentCoverage skipped for {:?} (not an fn-like)", mir_source.def_id());
55+
if !tcx.def_kind(def_id).is_fn_like() {
56+
trace!("InstrumentCoverage skipped for {def_id:?} (not an fn-like)");
5857
return;
5958
}
6059

@@ -66,14 +65,13 @@ impl<'tcx> MirPass<'tcx> for InstrumentCoverage {
6665
_ => {}
6766
}
6867

69-
let codegen_fn_attrs = tcx.codegen_fn_attrs(mir_source.def_id());
70-
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NO_COVERAGE) {
68+
if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::NO_COVERAGE) {
7169
return;
7270
}
7371

74-
trace!("InstrumentCoverage starting for {:?}", mir_source.def_id());
72+
trace!("InstrumentCoverage starting for {def_id:?}");
7573
Instrumentor::new(tcx, mir_body).inject_counters();
76-
trace!("InstrumentCoverage done for {:?}", mir_source.def_id());
74+
trace!("InstrumentCoverage done for {def_id:?}");
7775
}
7876
}
7977

0 commit comments

Comments
 (0)