@@ -107,6 +107,12 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
107107 ) ;
108108
109109 let mappings = self . create_mappings ( & coverage_spans, & coverage_counters) ;
110+ if mappings. is_empty ( ) {
111+ // No spans could be converted into valid mappings, so skip this function.
112+ debug ! ( "no spans could be converted into valid mappings; skipping" ) ;
113+ return ;
114+ }
115+
110116 self . inject_coverage_statements ( bcb_has_coverage_spans, & coverage_counters) ;
111117
112118 self . mir_body . function_coverage_info = Some ( Box :: new ( FunctionCoverageInfo {
@@ -148,9 +154,9 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
148154 // Flatten the spans into individual term/span pairs.
149155 . flat_map ( |( term, spans) | spans. iter ( ) . map ( move |& span| ( term, span) ) )
150156 // Convert each span to a code region, and create the final mapping.
151- . map ( |( term, span) | {
152- let code_region = make_code_region ( source_map, file_name, span, body_span) ;
153- Mapping { term, code_region }
157+ . filter_map ( |( term, span) | {
158+ let code_region = make_code_region ( source_map, file_name, span, body_span) ? ;
159+ Some ( Mapping { term, code_region } )
154160 } )
155161 . collect :: < Vec < _ > > ( )
156162 }
@@ -258,7 +264,7 @@ fn make_code_region(
258264 file_name : Symbol ,
259265 span : Span ,
260266 body_span : Span ,
261- ) -> CodeRegion {
267+ ) -> Option < CodeRegion > {
262268 debug ! (
263269 "Called make_code_region(file_name={}, span={}, body_span={})" ,
264270 file_name,
@@ -280,13 +286,13 @@ fn make_code_region(
280286 start_line = source_map. doctest_offset_line ( & file. name , start_line) ;
281287 end_line = source_map. doctest_offset_line ( & file. name , end_line) ;
282288 }
283- CodeRegion {
289+ Some ( CodeRegion {
284290 file_name,
285291 start_line : start_line as u32 ,
286292 start_col : start_col as u32 ,
287293 end_line : end_line as u32 ,
288294 end_col : end_col as u32 ,
289- }
295+ } )
290296}
291297
292298fn is_eligible_for_coverage ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> bool {
0 commit comments