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