coverage: Use SpanMarker
to mark continue
expressions.
This replaces the previous workaround, which was to inject a dummy `Assign` statement.
This commit is contained in:
parent
44b47aa976
commit
98166358a9
@ -90,7 +90,6 @@ use rustc_index::{IndexSlice, IndexVec};
|
|||||||
use rustc_middle::middle::region;
|
use rustc_middle::middle::region;
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::thir::{Expr, LintLevel};
|
use rustc_middle::thir::{Expr, LintLevel};
|
||||||
use rustc_middle::ty::Ty;
|
|
||||||
use rustc_session::lint::Level;
|
use rustc_session::lint::Level;
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
|
|
||||||
@ -660,14 +659,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
(None, Some(_)) => {
|
(None, Some(_)) => {
|
||||||
panic!("`return`, `become` and `break` with value and must have a destination")
|
panic!("`return`, `become` and `break` with value and must have a destination")
|
||||||
}
|
}
|
||||||
(None, None) if self.tcx.sess.instrument_coverage() => {
|
(None, None) => {
|
||||||
// Unlike `break` and `return`, which push an `Assign` statement to MIR, from which
|
if self.tcx.sess.instrument_coverage() {
|
||||||
// a Coverage code region can be generated, `continue` needs no `Assign`; but
|
// Normally we wouldn't build any MIR in this case, but that makes it
|
||||||
// without one, the `InstrumentCoverage` MIR pass cannot generate a code region for
|
// harder for coverage instrumentation to extract a relevant span for
|
||||||
// `continue`. Coverage will be missing unless we add a dummy `Assign` to MIR.
|
// `continue` expressions. So here we inject a dummy statement with the
|
||||||
self.add_dummy_assignment(span, block, source_info);
|
// desired span.
|
||||||
|
self.cfg.push_coverage_span_marker(block, source_info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(None, None) => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let region_scope = self.scopes.breakable_scopes[break_index].region_scope;
|
let region_scope = self.scopes.breakable_scopes[break_index].region_scope;
|
||||||
@ -723,14 +723,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
self.cfg.terminate(block, source_info, TerminatorKind::UnwindResume);
|
self.cfg.terminate(block, source_info, TerminatorKind::UnwindResume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a dummy `Assign` statement to the CFG, with the span for the source code's `continue`
|
|
||||||
// statement.
|
|
||||||
fn add_dummy_assignment(&mut self, span: Span, block: BasicBlock, source_info: SourceInfo) {
|
|
||||||
let local_decl = LocalDecl::new(Ty::new_unit(self.tcx), span);
|
|
||||||
let temp_place = Place::from(self.local_decls.push(local_decl));
|
|
||||||
self.cfg.push_assign_unit(block, source_info, temp_place, self.tcx);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn leave_top_scope(&mut self, block: BasicBlock) -> BasicBlock {
|
fn leave_top_scope(&mut self, block: BasicBlock) -> BasicBlock {
|
||||||
// If we are emitting a `drop` statement, we need to have the cached
|
// If we are emitting a `drop` statement, we need to have the cached
|
||||||
// diverge cleanup pads ready in case that drop panics.
|
// diverge cleanup pads ready in case that drop panics.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user