@@ -15,27 +15,26 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
1515 basic_coverage_blocks : & CoverageGraph ,
1616) -> Vec < CoverageSpan > {
1717 let & ExtractedHirInfo { is_async_fn, fn_sig_span, body_span, .. } = hir_info;
18+
19+ let mut initial_spans = vec ! [ CoverageSpan :: for_fn_sig( fn_sig_span) ] ;
20+
1821 if is_async_fn {
1922 // An async function desugars into a function that returns a future,
2023 // with the user code wrapped in a closure. Any spans in the desugared
21- // outer function will be unhelpful, so just produce a single span
22- // associating the function signature with its entry BCB.
23- return vec ! [ CoverageSpan :: for_fn_sig( fn_sig_span) ] ;
24- }
25-
26- let mut initial_spans = Vec :: with_capacity ( mir_body. basic_blocks . len ( ) * 2 ) ;
27- for ( bcb, bcb_data) in basic_coverage_blocks. iter_enumerated ( ) {
28- initial_spans. extend ( bcb_to_initial_coverage_spans ( mir_body, body_span, bcb, bcb_data) ) ;
29- }
24+ // outer function will be unhelpful, so just keep the signature span
25+ // and ignore all of the spans in the MIR body.
26+ } else {
27+ for ( bcb, bcb_data) in basic_coverage_blocks. iter_enumerated ( ) {
28+ initial_spans. extend ( bcb_to_initial_coverage_spans ( mir_body, body_span, bcb, bcb_data) ) ;
29+ }
3030
31- if initial_spans. is_empty ( ) {
32- // This can happen if, for example, the function is unreachable (contains only a
33- // `BasicBlock`(s) with an `Unreachable` terminator).
34- return initial_spans;
31+ // If no spans were extracted from the body, discard the signature span.
32+ // FIXME: This preserves existing behavior; consider getting rid of it.
33+ if initial_spans. len ( ) == 1 {
34+ initial_spans. clear ( ) ;
35+ }
3536 }
3637
37- initial_spans. push ( CoverageSpan :: for_fn_sig ( fn_sig_span) ) ;
38-
3938 initial_spans. sort_by ( |a, b| {
4039 // First sort by span start.
4140 Ord :: cmp ( & a. span . lo ( ) , & b. span . lo ( ) )
0 commit comments