@@ -527,17 +527,25 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
527527 . iter ( )
528528 . enumerate ( )
529529 . 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+ } )
537540 } )
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+ } ) )
541549 } )
542550 . collect ( )
543551 }
@@ -792,13 +800,9 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
792800 }
793801}
794802
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 > {
802806 match statement. kind {
803807 // These statements have spans that are often outside the scope of the executed source code
804808 // for their parent `BasicBlock`.
@@ -835,18 +839,14 @@ pub(super) fn filtered_statement_span(
835839 | StatementKind :: LlvmInlineAsm ( _)
836840 | StatementKind :: Retag ( _, _)
837841 | StatementKind :: AscribeUserType ( _, _) => {
838- Some ( function_source_span ( statement. source_info . span , body_span ) )
842+ Some ( statement. source_info . span )
839843 }
840844 }
841845}
842846
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 > {
850850 match terminator. kind {
851851 // These terminators have spans that don't positively contribute to computing a reasonable
852852 // span of actually executed source code. (For example, SwitchInt terminators extracted from
@@ -870,7 +870,7 @@ pub(super) fn filtered_terminator_span(
870870 span = span. with_lo ( constant. span . lo ( ) ) ;
871871 }
872872 }
873- Some ( function_source_span ( span, body_span ) )
873+ Some ( span)
874874 }
875875
876876 // Retain spans from all other terminators
@@ -881,28 +881,20 @@ pub(super) fn filtered_terminator_span(
881881 | TerminatorKind :: GeneratorDrop
882882 | TerminatorKind :: FalseUnwind { .. }
883883 | TerminatorKind :: InlineAsm { .. } => {
884- Some ( function_source_span ( terminator. source_info . span , body_span ) )
884+ Some ( terminator. source_info . span )
885885 }
886886 }
887887}
888888
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.
901893///
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.).
904896#[ 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 {
906898 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 }
908900}
0 commit comments