@@ -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 ;
@@ -311,6 +299,7 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
311299#[ derive( Debug ) ]
312300struct ExtractedHirInfo {
313301 function_source_hash : u64 ,
302+ is_async_fn : bool ,
314303 fn_sig_span : Span ,
315304 body_span : Span ,
316305}
@@ -324,6 +313,7 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
324313 hir:: map:: associated_body ( hir_node) . expect ( "HIR node is a function with body" ) ;
325314 let hir_body = tcx. hir ( ) . body ( fn_body_id) ;
326315
316+ let is_async_fn = hir_node. fn_sig ( ) . is_some_and ( |fn_sig| fn_sig. header . is_async ( ) ) ;
327317 let body_span = get_body_span ( tcx, hir_body, def_id) ;
328318
329319 // The actual signature span is only used if it has the same context and
@@ -345,7 +335,7 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
345335
346336 let function_source_hash = hash_mir_source ( tcx, hir_body) ;
347337
348- ExtractedHirInfo { function_source_hash, fn_sig_span, body_span }
338+ ExtractedHirInfo { function_source_hash, is_async_fn , fn_sig_span, body_span }
349339}
350340
351341fn get_body_span < ' tcx > (
0 commit comments