@@ -26,11 +26,9 @@ pub(super) fn extract_refined_covspans<'tcx>(
2626 return ;
2727 }
2828
29- let & ExtractedHirInfo { body_span, .. } = hir_info;
30-
3129 // If there somehow isn't an expansion tree node corresponding to the
3230 // body span, return now and don't create any mappings.
33- let Some ( node) = expn_tree. get ( body_span. ctxt ( ) . outer_expn ( ) ) else { return } ;
31+ let Some ( node) = expn_tree. get ( hir_info . body_span . ctxt ( ) . outer_expn ( ) ) else { return } ;
3432
3533 let mut covspans = vec ! [ ] ;
3634
@@ -47,27 +45,29 @@ pub(super) fn extract_refined_covspans<'tcx>(
4745 }
4846 }
4947
50- covspans. retain ( |covspan : & Covspan | {
51- let covspan_span = covspan. span ;
52- // Discard any spans not contained within the function body span.
53- // Also discard any spans that fill the entire body, because they tend
54- // to represent compiler-inserted code, e.g. implicitly returning `()`.
55- if !body_span. contains ( covspan_span) || body_span. source_equal ( covspan_span) {
56- return false ;
57- }
48+ if let Some ( body_span) = node. body_span {
49+ covspans. retain ( |covspan : & Covspan | {
50+ let covspan_span = covspan. span ;
51+ // Discard any spans not contained within the function body span.
52+ // Also discard any spans that fill the entire body, because they tend
53+ // to represent compiler-inserted code, e.g. implicitly returning `()`.
54+ if !body_span. contains ( covspan_span) || body_span. source_equal ( covspan_span) {
55+ return false ;
56+ }
5857
59- // Each pushed covspan should have the same context as the body span.
60- // If it somehow doesn't, discard the covspan, or panic in debug builds.
61- if !body_span. eq_ctxt ( covspan_span) {
62- debug_assert ! (
63- false ,
64- "span context mismatch: body_span={body_span:?}, covspan.span={covspan_span:?}"
65- ) ;
66- return false ;
67- }
58+ // Each pushed covspan should have the same context as the body span.
59+ // If it somehow doesn't, discard the covspan, or panic in debug builds.
60+ if !body_span. eq_ctxt ( covspan_span) {
61+ debug_assert ! (
62+ false ,
63+ "span context mismatch: body_span={body_span:?}, covspan.span={covspan_span:?}"
64+ ) ;
65+ return false ;
66+ }
6867
69- true
70- } ) ;
68+ true
69+ } ) ;
70+ }
7171
7272 // Only proceed if we found at least one usable span.
7373 if covspans. is_empty ( ) {
@@ -78,10 +78,9 @@ pub(super) fn extract_refined_covspans<'tcx>(
7878 // Otherwise, add a fake span at the start of the body, to avoid an ugly
7979 // gap between the start of the body and the first real span.
8080 // FIXME: Find a more principled way to solve this problem.
81- covspans. push ( Covspan {
82- span : hir_info. fn_sig_span . unwrap_or_else ( || body_span. shrink_to_lo ( ) ) ,
83- bcb : START_BCB ,
84- } ) ;
81+ if let Some ( span) = node. fn_sig_span . or_else ( || try { node. body_span ?. shrink_to_lo ( ) } ) {
82+ covspans. push ( Covspan { span, bcb : START_BCB } ) ;
83+ }
8584
8685 let compare_covspans = |a : & Covspan , b : & Covspan | {
8786 compare_spans ( a. span , b. span )
0 commit comments