@@ -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,7 @@ 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 ( tcx, def) ,
810815 } ;
811816
812817 assert_eq ! ( builder. cfg. start_new_block( ) , START_BLOCK ) ;
@@ -826,7 +831,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
826831 }
827832 }
828833
829- Body :: new (
834+ let mut body = Body :: new (
830835 MirSource :: item ( self . def_id . to_def_id ( ) ) ,
831836 self . cfg . basic_blocks ,
832837 self . source_scopes ,
@@ -837,7 +842,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
837842 self . fn_span ,
838843 self . coroutine ,
839844 None ,
840- )
845+ ) ;
846+ body. coverage_hir_branch_info = self . coverage_branch_info . and_then ( |b| b. into_done ( ) ) ;
847+ body
841848 }
842849
843850 fn insert_upvar_arg ( & mut self ) {
@@ -1111,6 +1118,7 @@ pub(crate) fn parse_float_into_scalar(
11111118
11121119mod block;
11131120mod cfg;
1121+ mod coverageinfo;
11141122mod custom;
11151123mod expr;
11161124mod matches;
0 commit comments