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