@@ -527,17 +527,25 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
527
527
. iter ( )
528
528
. enumerate ( )
529
529
. filter_map ( move |( index, statement) | {
530
- filtered_statement_span ( statement, self . body_span ) . map (
531
- |( span, expn_span) | {
532
- CoverageSpan :: for_statement (
533
- statement, span, expn_span, bcb, bb, index,
534
- )
535
- } ,
536
- )
530
+ filtered_statement_span ( statement) . map ( |span| {
531
+ CoverageSpan :: for_statement (
532
+ statement,
533
+ function_source_span ( span, self . body_span ) ,
534
+ span,
535
+ bcb,
536
+ bb,
537
+ index,
538
+ )
539
+ } )
537
540
} )
538
- . chain ( filtered_terminator_span ( data. terminator ( ) , self . body_span ) . map (
539
- |( span, expn_span) | CoverageSpan :: for_terminator ( span, expn_span, bcb, bb) ,
540
- ) )
541
+ . chain ( filtered_terminator_span ( data. terminator ( ) ) . map ( |span| {
542
+ CoverageSpan :: for_terminator (
543
+ function_source_span ( span, self . body_span ) ,
544
+ span,
545
+ bcb,
546
+ bb,
547
+ )
548
+ } ) )
541
549
} )
542
550
. collect ( )
543
551
}
@@ -792,13 +800,9 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
792
800
}
793
801
}
794
802
795
- /// See `function_source_span()` for a description of the two returned spans.
796
- /// If the MIR `Statement` is not contributive to computing coverage spans,
797
- /// returns `None`.
798
- pub ( super ) fn filtered_statement_span (
799
- statement : & ' a Statement < ' tcx > ,
800
- body_span : Span ,
801
- ) -> Option < ( Span , Span ) > {
803
+ /// If the MIR `Statement` has a span contributive to computing coverage spans,
804
+ /// return it; otherwise return `None`.
805
+ pub ( super ) fn filtered_statement_span ( statement : & ' a Statement < ' tcx > ) -> Option < Span > {
802
806
match statement. kind {
803
807
// These statements have spans that are often outside the scope of the executed source code
804
808
// for their parent `BasicBlock`.
@@ -835,18 +839,14 @@ pub(super) fn filtered_statement_span(
835
839
| StatementKind :: LlvmInlineAsm ( _)
836
840
| StatementKind :: Retag ( _, _)
837
841
| StatementKind :: AscribeUserType ( _, _) => {
838
- Some ( function_source_span ( statement. source_info . span , body_span ) )
842
+ Some ( statement. source_info . span )
839
843
}
840
844
}
841
845
}
842
846
843
- /// See `function_source_span()` for a description of the two returned spans.
844
- /// If the MIR `Terminator` is not contributive to computing coverage spans,
845
- /// returns `None`.
846
- pub ( super ) fn filtered_terminator_span (
847
- terminator : & ' a Terminator < ' tcx > ,
848
- body_span : Span ,
849
- ) -> Option < ( Span , Span ) > {
847
+ /// If the MIR `Terminator` has a span contributive to computing coverage spans,
848
+ /// return it; otherwise return `None`.
849
+ pub ( super ) fn filtered_terminator_span ( terminator : & ' a Terminator < ' tcx > ) -> Option < Span > {
850
850
match terminator. kind {
851
851
// These terminators have spans that don't positively contribute to computing a reasonable
852
852
// span of actually executed source code. (For example, SwitchInt terminators extracted from
@@ -870,7 +870,7 @@ pub(super) fn filtered_terminator_span(
870
870
span = span. with_lo ( constant. span . lo ( ) ) ;
871
871
}
872
872
}
873
- Some ( function_source_span ( span, body_span ) )
873
+ Some ( span)
874
874
}
875
875
876
876
// Retain spans from all other terminators
@@ -881,28 +881,20 @@ pub(super) fn filtered_terminator_span(
881
881
| TerminatorKind :: GeneratorDrop
882
882
| TerminatorKind :: FalseUnwind { .. }
883
883
| TerminatorKind :: InlineAsm { .. } => {
884
- Some ( function_source_span ( terminator. source_info . span , body_span ) )
884
+ Some ( terminator. source_info . span )
885
885
}
886
886
}
887
887
}
888
888
889
- /// Returns two spans from the given span (the span associated with a
890
- /// `Statement` or `Terminator`):
891
- ///
892
- /// 1. An extrapolated span (pre-expansion[^1]) corresponding to a range within
893
- /// the function's body source. This span is guaranteed to be contained
894
- /// within, or equal to, the `body_span`. If the extrapolated span is not
895
- /// contained within the `body_span`, the `body_span` is returned.
896
- /// 2. The actual `span` value from the `Statement`, before expansion.
897
- ///
898
- /// Only the first span is used when computing coverage code regions. The second
899
- /// span is useful if additional expansion data is needed (such as to look up
900
- /// the macro name for a composed span within that macro).)
889
+ /// Returns an extrapolated span (pre-expansion[^1]) corresponding to a range
890
+ /// within the function's body source. This span is guaranteed to be contained
891
+ /// within, or equal to, the `body_span`. If the extrapolated span is not
892
+ /// contained within the `body_span`, the `body_span` is returned.
901
893
///
902
- /// [^1]Expansions result from Rust syntax including macros, syntactic
903
- /// sugar, etc.).
894
+ /// [^1]Expansions result from Rust syntax including macros, syntactic sugar,
895
+ /// etc.).
904
896
#[ inline]
905
- fn function_source_span ( span : Span , body_span : Span ) -> ( Span , Span ) {
897
+ pub ( super ) fn function_source_span ( span : Span , body_span : Span ) -> Span {
906
898
let original_span = original_sp ( span, body_span) . with_ctxt ( body_span. ctxt ( ) ) ;
907
- ( if body_span. contains ( original_span) { original_span } else { body_span } , span )
899
+ if body_span. contains ( original_span) { original_span } else { body_span }
908
900
}
0 commit comments