@@ -68,41 +68,29 @@ impl<'tcx> MirPass<'tcx> for InstrumentCoverage {
68
68
struct Instrumentor < ' a , ' tcx > {
69
69
tcx : TyCtxt < ' tcx > ,
70
70
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 ,
74
72
basic_coverage_blocks : CoverageGraph ,
75
73
coverage_counters : CoverageCounters ,
76
74
}
77
75
78
76
impl < ' a , ' tcx > Instrumentor < ' a , ' tcx > {
79
77
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 ( ) ) ;
82
79
83
80
debug ! ( ?hir_info, "instrumenting {:?}" , mir_body. source. def_id( ) ) ;
84
81
85
82
let basic_coverage_blocks = CoverageGraph :: from_mir ( mir_body) ;
86
83
let coverage_counters = CoverageCounters :: new ( & basic_coverage_blocks) ;
87
84
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 }
97
86
}
98
87
99
88
fn inject_counters ( & ' a mut self ) {
100
89
////////////////////////////////////////////////////
101
90
// Compute coverage spans from the `CoverageGraph`.
102
91
let Some ( coverage_spans) = CoverageSpans :: generate_coverage_spans (
103
92
self . mir_body ,
104
- self . fn_sig_span ,
105
- self . body_span ,
93
+ & self . hir_info ,
106
94
& self . basic_coverage_blocks ,
107
95
) else {
108
96
// No relevant spans were found in MIR, so skip instrumenting this function.
@@ -121,7 +109,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
121
109
let mappings = self . create_mappings_and_inject_coverage_statements ( & coverage_spans) ;
122
110
123
111
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 ,
125
113
num_counters : self . coverage_counters . num_counters ( ) ,
126
114
expressions : self . coverage_counters . take_expressions ( ) ,
127
115
mappings,
@@ -136,7 +124,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
136
124
coverage_spans : & CoverageSpans ,
137
125
) -> Vec < Mapping > {
138
126
let source_map = self . tcx . sess . source_map ( ) ;
139
- let body_span = self . body_span ;
127
+ let body_span = self . hir_info . body_span ;
140
128
141
129
let source_file = source_map. lookup_source_file ( body_span. lo ( ) ) ;
142
130
use rustc_session:: RemapFileNameExt ;
@@ -311,6 +299,7 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
311
299
#[ derive( Debug ) ]
312
300
struct ExtractedHirInfo {
313
301
function_source_hash : u64 ,
302
+ is_async_fn : bool ,
314
303
fn_sig_span : Span ,
315
304
body_span : Span ,
316
305
}
@@ -324,6 +313,7 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
324
313
hir:: map:: associated_body ( hir_node) . expect ( "HIR node is a function with body" ) ;
325
314
let hir_body = tcx. hir ( ) . body ( fn_body_id) ;
326
315
316
+ let is_async_fn = hir_node. fn_sig ( ) . is_some_and ( |fn_sig| fn_sig. header . is_async ( ) ) ;
327
317
let body_span = get_body_span ( tcx, hir_body, def_id) ;
328
318
329
319
// 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
345
335
346
336
let function_source_hash = hash_mir_source ( tcx, hir_body) ;
347
337
348
- ExtractedHirInfo { function_source_hash, fn_sig_span, body_span }
338
+ ExtractedHirInfo { function_source_hash, is_async_fn , fn_sig_span, body_span }
349
339
}
350
340
351
341
fn get_body_span < ' tcx > (
0 commit comments