@@ -107,6 +107,12 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
107
107
) ;
108
108
109
109
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
+
110
116
self . inject_coverage_statements ( bcb_has_coverage_spans, & coverage_counters) ;
111
117
112
118
self . mir_body . function_coverage_info = Some ( Box :: new ( FunctionCoverageInfo {
@@ -148,9 +154,9 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
148
154
// Flatten the spans into individual term/span pairs.
149
155
. flat_map ( |( term, spans) | spans. iter ( ) . map ( move |& span| ( term, span) ) )
150
156
// 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 } )
154
160
} )
155
161
. collect :: < Vec < _ > > ( )
156
162
}
@@ -258,7 +264,7 @@ fn make_code_region(
258
264
file_name : Symbol ,
259
265
span : Span ,
260
266
body_span : Span ,
261
- ) -> CodeRegion {
267
+ ) -> Option < CodeRegion > {
262
268
debug ! (
263
269
"Called make_code_region(file_name={}, span={}, body_span={})" ,
264
270
file_name,
@@ -280,13 +286,13 @@ fn make_code_region(
280
286
start_line = source_map. doctest_offset_line ( & file. name , start_line) ;
281
287
end_line = source_map. doctest_offset_line ( & file. name , end_line) ;
282
288
}
283
- CodeRegion {
289
+ Some ( CodeRegion {
284
290
file_name,
285
291
start_line : start_line as u32 ,
286
292
start_col : start_col as u32 ,
287
293
end_line : end_line as u32 ,
288
294
end_col : end_col as u32 ,
289
- }
295
+ } )
290
296
}
291
297
292
298
fn is_eligible_for_coverage ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> bool {
0 commit comments