@@ -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,9 @@ 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_and_eligible (
815
+ tcx, def,
816
+ ) ,
810
817
} ;
811
818
812
819
assert_eq ! ( builder. cfg. start_new_block( ) , START_BLOCK ) ;
@@ -826,7 +833,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
826
833
}
827
834
}
828
835
829
- Body :: new (
836
+ let mut body = Body :: new (
830
837
MirSource :: item ( self . def_id . to_def_id ( ) ) ,
831
838
self . cfg . basic_blocks ,
832
839
self . source_scopes ,
@@ -837,7 +844,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
837
844
self . fn_span ,
838
845
self . coroutine ,
839
846
None ,
840
- )
847
+ ) ;
848
+ body. coverage_hir_branch_info = self . coverage_branch_info . and_then ( |b| b. into_done ( ) ) ;
849
+ body
841
850
}
842
851
843
852
fn insert_upvar_arg ( & mut self ) {
@@ -1111,6 +1120,7 @@ pub(crate) fn parse_float_into_scalar(
1111
1120
1112
1121
mod block;
1113
1122
mod cfg;
1123
+ mod coverageinfo;
1114
1124
mod custom;
1115
1125
mod expr;
1116
1126
mod matches;
0 commit comments