Adjust MIR validator to check a few more things for terminators
This commit is contained in:
parent
f1f25c0f81
commit
f2d7908ff7
1 changed files with 19 additions and 5 deletions
|
@ -642,6 +642,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TerminatorKind::Yield { resume, drop, .. } => {
|
TerminatorKind::Yield { resume, drop, .. } => {
|
||||||
|
if self.body.generator.is_none() {
|
||||||
|
self.fail(location, "`Yield` cannot appear outside generator bodies");
|
||||||
|
}
|
||||||
if self.mir_phase >= MirPhase::GeneratorsLowered {
|
if self.mir_phase >= MirPhase::GeneratorsLowered {
|
||||||
self.fail(location, "`Yield` should have been replaced by generator lowering");
|
self.fail(location, "`Yield` should have been replaced by generator lowering");
|
||||||
}
|
}
|
||||||
|
@ -681,6 +684,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TerminatorKind::GeneratorDrop => {
|
TerminatorKind::GeneratorDrop => {
|
||||||
|
if self.body.generator.is_none() {
|
||||||
|
self.fail(location, "`GeneratorDrop` cannot appear outside generator bodies");
|
||||||
|
}
|
||||||
if self.mir_phase >= MirPhase::GeneratorsLowered {
|
if self.mir_phase >= MirPhase::GeneratorsLowered {
|
||||||
self.fail(
|
self.fail(
|
||||||
location,
|
location,
|
||||||
|
@ -688,11 +694,19 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Nothing to validate for these.
|
TerminatorKind::Resume | TerminatorKind::Abort => {
|
||||||
TerminatorKind::Resume
|
let bb = location.block;
|
||||||
| TerminatorKind::Abort
|
if !self.body.basic_blocks()[bb].is_cleanup {
|
||||||
| TerminatorKind::Return
|
self.fail(location, "Cannot `Resume` from non-cleanup basic block")
|
||||||
| TerminatorKind::Unreachable => {}
|
}
|
||||||
|
}
|
||||||
|
TerminatorKind::Return => {
|
||||||
|
let bb = location.block;
|
||||||
|
if self.body.basic_blocks()[bb].is_cleanup {
|
||||||
|
self.fail(location, "Cannot `Return` from cleanup basic block")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TerminatorKind::Unreachable => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.super_terminator(terminator, location);
|
self.super_terminator(terminator, location);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue