about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2023-12-14 10:47:10 +1100
committerZalathar <Zalathar@users.noreply.github.com>2023-12-15 10:59:32 +1100
commit315c0cf358b69fb2dd799025f682404a9a083d62 (patch)
treeb638c898712e7ca997ad14fb295ee09f4a1faa74
parent87cffb237774010e5761a07d884419e8993b2f45 (diff)
downloadrust-315c0cf358b69fb2dd799025f682404a9a083d62.tar.gz
rust-315c0cf358b69fb2dd799025f682404a9a083d62.zip
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
-rw-r--r--compiler/rustc_mir_transform/src/coverage/mod.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs
index d3a36a9511e..fbd9adeb2a4 100644
--- a/compiler/rustc_mir_transform/src/coverage/mod.rs
+++ b/compiler/rustc_mir_transform/src/coverage/mod.rs
@@ -43,8 +43,7 @@ impl<'tcx> MirPass<'tcx> for InstrumentCoverage {
         // be transformed, so it should never see promoted MIR.
         assert!(mir_source.promoted.is_none());
 
-        let is_fn_like =
-            tcx.hir_node_by_def_id(mir_source.def_id().expect_local()).fn_kind().is_some();
+        let def_id = mir_source.def_id().expect_local();
 
         // Only instrument functions, methods, and closures (not constants since they are evaluated
         // at compile time by Miri).
@@ -53,8 +52,8 @@ impl<'tcx> MirPass<'tcx> for InstrumentCoverage {
         // expressions from coverage spans in enclosing MIR's, like we do for closures. (That might
         // be tricky if const expressions have no corresponding statements in the enclosing MIR.
         // Closures are carved out by their initial `Assign` statement.)
-        if !is_fn_like {
-            trace!("InstrumentCoverage skipped for {:?} (not an fn-like)", mir_source.def_id());
+        if !tcx.def_kind(def_id).is_fn_like() {
+            trace!("InstrumentCoverage skipped for {def_id:?} (not an fn-like)");
             return;
         }
 
@@ -66,14 +65,13 @@ impl<'tcx> MirPass<'tcx> for InstrumentCoverage {
             _ => {}
         }
 
-        let codegen_fn_attrs = tcx.codegen_fn_attrs(mir_source.def_id());
-        if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NO_COVERAGE) {
+        if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::NO_COVERAGE) {
             return;
         }
 
-        trace!("InstrumentCoverage starting for {:?}", mir_source.def_id());
+        trace!("InstrumentCoverage starting for {def_id:?}");
         Instrumentor::new(tcx, mir_body).inject_counters();
-        trace!("InstrumentCoverage done for {:?}", mir_source.def_id());
+        trace!("InstrumentCoverage done for {def_id:?}");
     }
 }