@@ -107,6 +107,7 @@ struct Instrumentor<'a, 'tcx> {
107
107
function_source_hash : u64 ,
108
108
basic_coverage_blocks : CoverageGraph ,
109
109
coverage_counters : CoverageCounters ,
110
+ mappings : Vec < ( CovTerm , CodeRegion ) > ,
110
111
}
111
112
112
113
impl < ' a , ' tcx > Instrumentor < ' a , ' tcx > {
@@ -148,6 +149,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
148
149
function_source_hash,
149
150
basic_coverage_blocks,
150
151
coverage_counters,
152
+ mappings : Vec :: new ( ) ,
151
153
}
152
154
}
153
155
@@ -276,6 +278,9 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
276
278
self . make_mir_coverage_kind ( intermediate_expression) ,
277
279
) ;
278
280
}
281
+
282
+ self . mir_body . coverage_info =
283
+ Some ( Box :: new ( FunctionCoverageInfo { mappings : std:: mem:: take ( & mut self . mappings ) } ) ) ;
279
284
}
280
285
281
286
/// Injects a single [`StatementKind::Coverage`] for each BCB that has one
@@ -305,20 +310,14 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
305
310
debug_used_expressions. add_expression_operands ( & counter_kind) ;
306
311
graphviz_data. add_bcb_coverage_spans_with_counter ( bcb, bcb_spans, & counter_kind) ;
307
312
308
- // Convert the coverage spans into a vector of code regions to be
309
- // associated with this BCB's coverage statement.
310
- let code_regions = bcb_spans
311
- . iter ( )
312
- . map ( |coverage_span| {
313
- make_code_region ( source_map, file_name, coverage_span. span , body_span)
314
- } )
315
- . collect :: < Vec < _ > > ( ) ;
313
+ let mapping_kind = counter_kind. as_term ( ) ;
314
+ self . mappings . extend ( bcb_spans. iter ( ) . map ( |coverage_span| {
315
+ (
316
+ mapping_kind,
317
+ make_code_region ( source_map, file_name, coverage_span. span , body_span) ,
318
+ )
319
+ } ) ) ;
316
320
317
- inject_statement (
318
- self . mir_body ,
319
- CoverageKind :: Mappings { kind : counter_kind. as_term ( ) , code_regions } ,
320
- mir:: START_BLOCK ,
321
- ) ;
322
321
inject_statement (
323
322
self . mir_body ,
324
323
self . make_mir_coverage_kind ( & counter_kind) ,
0 commit comments