@@ -16,27 +16,26 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
1616 basic_coverage_blocks : & CoverageGraph ,
1717) -> Vec < CoverageSpan > {
1818 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+
1922 if is_async_fn {
2023 // An async function desugars into a function that returns a future,
2124 // 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+ }
3131
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+ }
3637 }
3738
38- initial_spans. push ( CoverageSpan :: for_fn_sig ( fn_sig_span) ) ;
39-
4039 initial_spans. sort_by ( |a, b| basic_coverage_blocks. cmp_in_dominator_order ( a. bcb , b. bcb ) ) ;
4140 remove_unwanted_macro_spans ( & mut initial_spans) ;
4241 split_visible_macro_spans ( & mut initial_spans, hir_info) ;
0 commit comments