@@ -106,8 +106,9 @@ impl BranchInfoBuilder {
106106 tcx : TyCtxt < ' _ > ,
107107 true_marker : BlockMarkerId ,
108108 false_marker : BlockMarkerId ,
109- ) -> Option < ConditionInfo > {
109+ ) -> Option < ( u16 , ConditionInfo ) > {
110110 let mcdc_state = self . mcdc_state . as_mut ( ) ?;
111+ let decision_depth = mcdc_state. decision_depth ;
111112 let ( mut condition_info, decision_result) =
112113 mcdc_state. take_condition ( true_marker, false_marker) ;
113114 if let Some ( decision) = decision_result {
@@ -141,7 +142,7 @@ impl BranchInfoBuilder {
141142 }
142143 }
143144 }
144- condition_info
145+ condition_info. map ( |cond_info| ( decision_depth , cond_info ) )
145146 }
146147
147148 fn next_block_marker_id ( & mut self ) -> BlockMarkerId {
@@ -183,13 +184,18 @@ struct MCDCState {
183184 /// To construct condition evaluation tree.
184185 decision_stack : VecDeque < ConditionInfo > ,
185186 processing_decision : Option < MCDCDecisionSpan > ,
187+ decision_depth : u16 ,
186188}
187189
188190impl MCDCState {
189191 fn new_if_enabled ( tcx : TyCtxt < ' _ > ) -> Option < Self > {
190192 tcx. sess
191193 . instrument_coverage_mcdc ( )
192- . then ( || Self { decision_stack : VecDeque :: new ( ) , processing_decision : None } )
194+ . then ( || Self {
195+ decision_stack : VecDeque :: new ( ) ,
196+ processing_decision : None ,
197+ decision_depth : 0 ,
198+ } )
193199 }
194200
195201 // At first we assign ConditionIds for each sub expression.
@@ -356,15 +362,15 @@ impl Builder<'_, '_> {
356362 let true_marker = inject_branch_marker ( then_block) ;
357363 let false_marker = inject_branch_marker ( else_block) ;
358364
359- if let Some ( condition_info) =
365+ if let Some ( ( decision_depth , condition_info) ) =
360366 branch_info. fetch_condition_info ( self . tcx , true_marker, false_marker)
361367 {
362368 branch_info. mcdc_branch_spans . push ( MCDCBranchSpan {
363369 span : source_info. span ,
364370 condition_info,
365371 true_marker,
366372 false_marker,
367- decision_depth : 0 ,
373+ decision_depth,
368374 } ) ;
369375 } else {
370376 branch_info. branch_spans . push ( BranchSpan {
@@ -380,4 +386,20 @@ impl Builder<'_, '_> {
380386 branch_info. record_conditions_operation ( logical_op, span) ;
381387 }
382388 }
389+
390+ pub ( crate ) fn mcdc_increment_depth_if_enabled ( & mut self ) {
391+ if let Some ( branch_info) = self . coverage_branch_info . as_mut ( )
392+ && let Some ( mcdc_state) = branch_info. mcdc_state . as_mut ( )
393+ {
394+ mcdc_state. decision_depth += 1 ;
395+ } ;
396+ }
397+
398+ pub ( crate ) fn mcdc_decrement_depth_if_enabled ( & mut self ) {
399+ if let Some ( branch_info) = self . coverage_branch_info . as_mut ( )
400+ && let Some ( mcdc_state) = branch_info. mcdc_state . as_mut ( )
401+ {
402+ mcdc_state. decision_depth -= 1 ;
403+ } ;
404+ }
383405}
0 commit comments