@@ -202,11 +202,11 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
202202 //
203203 // Intermediate expressions (used to compute other `Expression` values), which have no
204204 // direct association with any `BasicCoverageBlock`, are accumulated inside `coverage_counters`.
205- let result = self
205+ let mut result = self
206206 . coverage_counters
207207 . make_bcb_counters ( & mut self . basic_coverage_blocks , & coverage_spans) ;
208208
209- if let Ok ( ( ) ) = result {
209+ if let Ok ( branches ) = result. as_mut ( ) {
210210 // If debugging, add any intermediate expressions (which are not associated with any
211211 // BCB) to the `debug_used_expressions` map.
212212 if debug_used_expressions. is_enabled ( ) {
@@ -231,6 +231,8 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
231231 & mut debug_used_expressions,
232232 ) ;
233233
234+ self . inject_branch_counters ( std:: mem:: take ( branches) ) ;
235+
234236 ////////////////////////////////////////////////////
235237 // For any remaining `BasicCoverageBlock` counters (that were not associated with
236238 // any `CoverageSpan`), inject `Coverage` statements (_without_ code region `Span`s)
@@ -275,6 +277,27 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
275277 }
276278 }
277279
280+ fn inject_branch_counters ( & mut self , branches : Vec < ( BasicCoverageBlock , CoverageKind ) > ) {
281+ let tcx = self . tcx ;
282+ let source_map = tcx. sess . source_map ( ) ;
283+ let body_span = self . body_span ;
284+ let file_name = Symbol :: intern ( & self . source_file . name . prefer_remapped ( ) . to_string_lossy ( ) ) ;
285+
286+ for branch in branches {
287+ let bcb_data = self . bcb_data ( branch. 0 ) ;
288+ let terminator = bcb_data. terminator ( self . mir_body ) ;
289+
290+ let span = terminator. source_info . span ;
291+
292+ // FIXME(swatinem): figure out what a good span for the conditional is.
293+ // For trivial code examples, the `terminator` seems to be sufficient.
294+ let code_region =
295+ Some ( make_code_region ( source_map, file_name, & self . source_file , span, body_span) ) ;
296+
297+ inject_statement ( self . mir_body , branch. 1 , bcb_data. last_bb ( ) , code_region) ;
298+ }
299+ }
300+
278301 /// Inject a counter for each `CoverageSpan`. There can be multiple `CoverageSpan`s for a given
279302 /// BCB, but only one actual counter needs to be incremented per BCB. `bb_counters` maps each
280303 /// `bcb` to its `Counter`, when injected. Subsequent `CoverageSpan`s for a BCB that already has
0 commit comments