Add coverage to continue statements
`continue` statements were missing coverage. This was particularly noticeable in a match pattern that contained only a `continue` statement, leaving the branch appear uncounted. This PR addresses the problem and adds tests to prove it.
This commit is contained in:
parent
83ca4b7e60
commit
448e52d97c
5 changed files with 160 additions and 2 deletions
|
@ -618,6 +618,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
}
|
||||
} else {
|
||||
assert!(value.is_none(), "`return` and `break` should have a destination");
|
||||
// `continue` statements generate no MIR statement with the `continue` statement's Span,
|
||||
// and the `InstrumentCoverage` statement will have no way to generate a coverage
|
||||
// code region for the `continue` statement, unless we add a dummy `Assign` here:
|
||||
let mut local_decl = LocalDecl::new(self.tcx.mk_unit(), span);
|
||||
local_decl = local_decl.immutable();
|
||||
let temp = self.local_decls.push(local_decl);
|
||||
let temp_place = Place::from(temp);
|
||||
self.cfg.push(block, Statement { source_info, kind: StatementKind::StorageLive(temp) });
|
||||
self.cfg.push_assign_unit(block, source_info, temp_place, self.tcx);
|
||||
self.cfg.push(block, Statement { source_info, kind: StatementKind::StorageDead(temp) });
|
||||
}
|
||||
|
||||
let region_scope = self.scopes.breakable_scopes[break_index].region_scope;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue