@@ -107,6 +107,7 @@ struct Instrumentor<'a, 'tcx> {
107107 function_source_hash : u64 ,
108108 basic_coverage_blocks : CoverageGraph ,
109109 coverage_counters : CoverageCounters ,
110+ mappings : Vec < ( CovTerm , CodeRegion ) > ,
110111}
111112
112113impl < ' a , ' tcx > Instrumentor < ' a , ' tcx > {
@@ -148,6 +149,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
148149 function_source_hash,
149150 basic_coverage_blocks,
150151 coverage_counters,
152+ mappings : Vec :: new ( ) ,
151153 }
152154 }
153155
@@ -276,6 +278,9 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
276278 self . make_mir_coverage_kind ( intermediate_expression) ,
277279 ) ;
278280 }
281+
282+ self . mir_body . coverage_info =
283+ Some ( Box :: new ( FunctionCoverageInfo { mappings : std:: mem:: take ( & mut self . mappings ) } ) ) ;
279284 }
280285
281286 /// Injects a single [`StatementKind::Coverage`] for each BCB that has one
@@ -305,20 +310,14 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
305310 debug_used_expressions. add_expression_operands ( & counter_kind) ;
306311 graphviz_data. add_bcb_coverage_spans_with_counter ( bcb, bcb_spans, & counter_kind) ;
307312
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+ } ) ) ;
316320
317- inject_statement (
318- self . mir_body ,
319- CoverageKind :: Mappings { kind : counter_kind. as_term ( ) , code_regions } ,
320- mir:: START_BLOCK ,
321- ) ;
322321 inject_statement (
323322 self . mir_body ,
324323 self . make_mir_coverage_kind ( & counter_kind) ,
0 commit comments