@@ -234,6 +234,10 @@ struct Builder<'a, 'tcx> {
234
234
// the root (most of them do) and saves us from retracing many sub-paths
235
235
// many times, and rechecking many nodes.
236
236
lint_level_roots_cache : GrowableBitSet < hir:: ItemLocalId > ,
237
+
238
+ /// Collects additional coverage information during MIR building.
239
+ /// Only present if branch coverage is enabled and this function is eligible.
240
+ coverage_branch_info : Option < coverageinfo:: HirBranchInfoBuilder > ,
237
241
}
238
242
239
243
type CaptureMap < ' tcx > = SortedIndexMultiMap < usize , hir:: HirId , Capture < ' tcx > > ;
@@ -807,6 +811,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
807
811
unit_temp : None ,
808
812
var_debug_info : vec ! [ ] ,
809
813
lint_level_roots_cache : GrowableBitSet :: new_empty ( ) ,
814
+ coverage_branch_info : coverageinfo:: HirBranchInfoBuilder :: new_if_enabled ( tcx, def) ,
810
815
} ;
811
816
812
817
assert_eq ! ( builder. cfg. start_new_block( ) , START_BLOCK ) ;
@@ -826,7 +831,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
826
831
}
827
832
}
828
833
829
- Body :: new (
834
+ let mut body = Body :: new (
830
835
MirSource :: item ( self . def_id . to_def_id ( ) ) ,
831
836
self . cfg . basic_blocks ,
832
837
self . source_scopes ,
@@ -837,7 +842,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
837
842
self . fn_span ,
838
843
self . coroutine ,
839
844
None ,
840
- )
845
+ ) ;
846
+ body. coverage_hir_branch_info = self . coverage_branch_info . and_then ( |b| b. into_done ( ) ) ;
847
+ body
841
848
}
842
849
843
850
fn insert_upvar_arg ( & mut self ) {
@@ -1111,6 +1118,7 @@ pub(crate) fn parse_float_into_scalar(
1111
1118
1112
1119
mod block;
1113
1120
mod cfg;
1121
+ mod coverageinfo;
1114
1122
mod custom;
1115
1123
mod expr;
1116
1124
mod matches;
0 commit comments