@@ -618,16 +618,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
618
618
}
619
619
} else {
620
620
assert ! ( value. is_none( ) , "`return` and `break` should have a destination" ) ;
621
- // `continue` statements generate no MIR statement with the `continue` statement's Span,
622
- // and the `InstrumentCoverage` statement will have no way to generate a coverage
623
- // code region for the `continue` statement, unless we add a dummy `Assign` here:
624
- let mut local_decl = LocalDecl :: new ( self . tcx . mk_unit ( ) , span) ;
625
- local_decl = local_decl. immutable ( ) ;
626
- let temp = self . local_decls . push ( local_decl) ;
627
- let temp_place = Place :: from ( temp) ;
628
- self . cfg . push ( block, Statement { source_info, kind : StatementKind :: StorageLive ( temp) } ) ;
629
- self . cfg . push_assign_unit ( block, source_info, temp_place, self . tcx ) ;
630
- self . cfg . push ( block, Statement { source_info, kind : StatementKind :: StorageDead ( temp) } ) ;
621
+ if self . tcx . sess . instrument_coverage ( ) {
622
+ // Unlike `break` and `return`, which push an `Assign` statement to MIR, from which
623
+ // a Coverage code region can be generated, `continue` needs no `Assign`; but
624
+ // without one, the `InstrumentCoverage` MIR pass cannot generate a code region for
625
+ // `continue`. Coverage will be missing unless we add a dummy `Assign` to MIR.
626
+ self . add_dummy_assignment ( & span, block, source_info) ;
627
+ }
631
628
}
632
629
633
630
let region_scope = self . scopes . breakable_scopes [ break_index] . region_scope ;
@@ -653,6 +650,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
653
650
self . cfg . start_new_block ( ) . unit ( )
654
651
}
655
652
653
+ // Add a dummy `Assign` statement to the CFG, with the span for the source code's `continue`
654
+ // statement.
655
+ fn add_dummy_assignment ( & mut self , span : & Span , block : BasicBlock , source_info : SourceInfo ) {
656
+ let local_decl = LocalDecl :: new ( self . tcx . mk_unit ( ) , * span) . internal ( ) ;
657
+ let temp_place = Place :: from ( self . local_decls . push ( local_decl) ) ;
658
+ self . cfg . push_assign_unit ( block, source_info, temp_place, self . tcx ) ;
659
+ }
660
+
656
661
crate fn exit_top_scope (
657
662
& mut self ,
658
663
mut block : BasicBlock ,
0 commit comments