@@ -15,27 +15,26 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
15
15
basic_coverage_blocks : & CoverageGraph ,
16
16
) -> Vec < CoverageSpan > {
17
17
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
+
18
21
if is_async_fn {
19
22
// An async function desugars into a function that returns a future,
20
23
// 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
+ }
30
30
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
+ }
35
36
}
36
37
37
- initial_spans. push ( CoverageSpan :: for_fn_sig ( fn_sig_span) ) ;
38
-
39
38
initial_spans. sort_by ( |a, b| {
40
39
// First sort by span start.
41
40
Ord :: cmp ( & a. span . lo ( ) , & b. span . lo ( ) )
0 commit comments