@@ -68,41 +68,29 @@ impl<'tcx> MirPass<'tcx> for InstrumentCoverage {
6868struct Instrumentor < ' a , ' tcx > {
6969 tcx : TyCtxt < ' tcx > ,
7070 mir_body : & ' a mut mir:: Body < ' tcx > ,
71- fn_sig_span : Span ,
72- body_span : Span ,
73- function_source_hash : u64 ,
71+ hir_info : ExtractedHirInfo ,
7472 basic_coverage_blocks : CoverageGraph ,
7573 coverage_counters : CoverageCounters ,
7674}
7775
7876impl < ' a , ' tcx > Instrumentor < ' a , ' tcx > {
7977 fn new ( tcx : TyCtxt < ' tcx > , mir_body : & ' a mut mir:: Body < ' tcx > ) -> Self {
80- let hir_info @ ExtractedHirInfo { function_source_hash, fn_sig_span, body_span } =
81- extract_hir_info ( tcx, mir_body. source . def_id ( ) . expect_local ( ) ) ;
78+ let hir_info = extract_hir_info ( tcx, mir_body. source . def_id ( ) . expect_local ( ) ) ;
8279
8380 debug ! ( ?hir_info, "instrumenting {:?}" , mir_body. source. def_id( ) ) ;
8481
8582 let basic_coverage_blocks = CoverageGraph :: from_mir ( mir_body) ;
8683 let coverage_counters = CoverageCounters :: new ( & basic_coverage_blocks) ;
8784
88- Self {
89- tcx,
90- mir_body,
91- fn_sig_span,
92- body_span,
93- function_source_hash,
94- basic_coverage_blocks,
95- coverage_counters,
96- }
85+ Self { tcx, mir_body, hir_info, basic_coverage_blocks, coverage_counters }
9786 }
9887
9988 fn inject_counters ( & ' a mut self ) {
10089 ////////////////////////////////////////////////////
10190 // Compute coverage spans from the `CoverageGraph`.
10291 let Some ( coverage_spans) = CoverageSpans :: generate_coverage_spans (
10392 self . mir_body ,
104- self . fn_sig_span ,
105- self . body_span ,
93+ & self . hir_info ,
10694 & self . basic_coverage_blocks ,
10795 ) else {
10896 // No relevant spans were found in MIR, so skip instrumenting this function.
@@ -121,7 +109,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
121109 let mappings = self . create_mappings_and_inject_coverage_statements ( & coverage_spans) ;
122110
123111 self . mir_body . function_coverage_info = Some ( Box :: new ( FunctionCoverageInfo {
124- function_source_hash : self . function_source_hash ,
112+ function_source_hash : self . hir_info . function_source_hash ,
125113 num_counters : self . coverage_counters . num_counters ( ) ,
126114 expressions : self . coverage_counters . take_expressions ( ) ,
127115 mappings,
@@ -136,7 +124,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
136124 coverage_spans : & CoverageSpans ,
137125 ) -> Vec < Mapping > {
138126 let source_map = self . tcx . sess . source_map ( ) ;
139- let body_span = self . body_span ;
127+ let body_span = self . hir_info . body_span ;
140128
141129 let source_file = source_map. lookup_source_file ( body_span. lo ( ) ) ;
142130 use rustc_session:: RemapFileNameExt ;
0 commit comments