@@ -15,8 +15,10 @@ mod from_mir;
1515pub ( super ) enum BcbMappingKind {
1616 /// Associates an ordinary executable code span with its corresponding BCB.
1717 Code ( BasicCoverageBlock ) ,
18- /// Associates a branch span with BCBs for its true and false arms.
19- Branch { true_bcb : BasicCoverageBlock , false_bcb : BasicCoverageBlock } ,
18+
19+ // Ordinary branch mappings are stored separately, so they don't have a
20+ // variant in this enum.
21+ //
2022 /// Associates a mcdc branch span with condition info besides fields for normal branch.
2123 MCDCBranch {
2224 true_bcb : BasicCoverageBlock ,
@@ -35,9 +37,20 @@ pub(super) struct BcbMapping {
3537 pub ( super ) span : Span ,
3638}
3739
40+ /// This is separate from [`BcbMappingKind`] to help prepare for larger changes
41+ /// that will be needed for improved branch coverage in the future.
42+ /// (See <https://github.com/rust-lang/rust/pull/124217>.)
43+ #[ derive( Debug ) ]
44+ pub ( super ) struct BcbBranchPair {
45+ pub ( super ) span : Span ,
46+ pub ( super ) true_bcb : BasicCoverageBlock ,
47+ pub ( super ) false_bcb : BasicCoverageBlock ,
48+ }
49+
3850pub ( super ) struct CoverageSpans {
3951 bcb_has_mappings : BitSet < BasicCoverageBlock > ,
40- mappings : Vec < BcbMapping > ,
52+ pub ( super ) mappings : Vec < BcbMapping > ,
53+ pub ( super ) branch_pairs : Vec < BcbBranchPair > ,
4154 test_vector_bitmap_bytes : u32 ,
4255}
4356
@@ -46,10 +59,6 @@ impl CoverageSpans {
4659 self . bcb_has_mappings . contains ( bcb)
4760 }
4861
49- pub ( super ) fn all_bcb_mappings ( & self ) -> impl Iterator < Item = & BcbMapping > {
50- self . mappings . iter ( )
51- }
52-
5362 pub ( super ) fn test_vector_bitmap_bytes ( & self ) -> u32 {
5463 self . test_vector_bitmap_bytes
5564 }
@@ -65,6 +74,7 @@ pub(super) fn generate_coverage_spans(
6574 basic_coverage_blocks : & CoverageGraph ,
6675) -> Option < CoverageSpans > {
6776 let mut mappings = vec ! [ ] ;
77+ let mut branch_pairs = vec ! [ ] ;
6878
6979 if hir_info. is_async_fn {
7080 // An async function desugars into a function that returns a future,
@@ -86,7 +96,7 @@ pub(super) fn generate_coverage_spans(
8696 BcbMapping { kind : BcbMappingKind :: Code ( bcb) , span }
8797 } ) ) ;
8898
89- mappings . extend ( from_mir:: extract_branch_mappings (
99+ branch_pairs . extend ( from_mir:: extract_branch_pairs (
90100 mir_body,
91101 hir_info,
92102 basic_coverage_blocks,
@@ -99,7 +109,7 @@ pub(super) fn generate_coverage_spans(
99109 ) ) ;
100110 }
101111
102- if mappings. is_empty ( ) {
112+ if mappings. is_empty ( ) && branch_pairs . is_empty ( ) {
103113 return None ;
104114 }
105115
@@ -112,8 +122,7 @@ pub(super) fn generate_coverage_spans(
112122 for BcbMapping { kind, span : _ } in & mappings {
113123 match * kind {
114124 BcbMappingKind :: Code ( bcb) => insert ( bcb) ,
115- BcbMappingKind :: Branch { true_bcb, false_bcb }
116- | BcbMappingKind :: MCDCBranch { true_bcb, false_bcb, .. } => {
125+ BcbMappingKind :: MCDCBranch { true_bcb, false_bcb, .. } => {
117126 insert ( true_bcb) ;
118127 insert ( false_bcb) ;
119128 }
@@ -126,8 +135,12 @@ pub(super) fn generate_coverage_spans(
126135 }
127136 }
128137 }
138+ for & BcbBranchPair { true_bcb, false_bcb, .. } in & branch_pairs {
139+ insert ( true_bcb) ;
140+ insert ( false_bcb) ;
141+ }
129142
130- Some ( CoverageSpans { bcb_has_mappings, mappings, test_vector_bitmap_bytes } )
143+ Some ( CoverageSpans { bcb_has_mappings, mappings, branch_pairs , test_vector_bitmap_bytes } )
131144}
132145
133146#[ derive( Debug ) ]
0 commit comments