@@ -234,6 +234,10 @@ struct Builder<'a, 'tcx> {
234234 // the root (most of them do) and saves us from retracing many sub-paths
235235 // many times, and rechecking many nodes.
236236 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 > ,
237241}
238242
239243type CaptureMap < ' tcx > = SortedIndexMultiMap < usize , hir:: HirId , Capture < ' tcx > > ;
@@ -807,6 +811,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
807811 unit_temp : None ,
808812 var_debug_info : vec ! [ ] ,
809813 lint_level_roots_cache : GrowableBitSet :: new_empty ( ) ,
814+ coverage_branch_info : coverageinfo:: HirBranchInfoBuilder :: new_if_enabled_and_eligible (
815+ tcx, def,
816+ ) ,
810817 } ;
811818
812819 assert_eq ! ( builder. cfg. start_new_block( ) , START_BLOCK ) ;
@@ -826,7 +833,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
826833 }
827834 }
828835
829- Body :: new (
836+ let mut body = Body :: new (
830837 MirSource :: item ( self . def_id . to_def_id ( ) ) ,
831838 self . cfg . basic_blocks ,
832839 self . source_scopes ,
@@ -837,7 +844,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
837844 self . fn_span ,
838845 self . coroutine ,
839846 None ,
840- )
847+ ) ;
848+ body. coverage_hir_branch_info = self . coverage_branch_info . and_then ( |b| b. into_done ( ) ) ;
849+ body
841850 }
842851
843852 fn insert_upvar_arg ( & mut self ) {
@@ -1111,6 +1120,7 @@ pub(crate) fn parse_float_into_scalar(
11111120
11121121mod block;
11131122mod cfg;
1123+ mod coverageinfo;
11141124mod custom;
11151125mod expr;
11161126mod matches;
0 commit comments