Skip to content

Commit

Permalink
more checks for SwitchInt
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 31, 2020
1 parent e07e424 commit 9a4bdbf
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/librustc_mir/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
TerminatorKind::Goto { target } => {
self.check_bb(terminator.source_info.span, *target);
}
TerminatorKind::SwitchInt { targets, .. } => {
if targets.is_empty() {
TerminatorKind::SwitchInt { targets, values, .. } => {
if targets.len() != values.len() + 1 {
self.fail(
terminator.source_info.span,
"encountered `SwitchInt` terminator with no target to jump to",
format!(
"encountered `SwitchInt` terminator with {} values, but {} targets (should be values+1)",
values.len(),
targets.len(),
),
);
}
for target in targets {
Expand Down

0 comments on commit 9a4bdbf

Please sign in to comment.