Skip to content

Commit 9a4bdbf

Browse files
committed
more checks for SwitchInt
1 parent e07e424 commit 9a4bdbf

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/librustc_mir/transform/validate.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
9090
TerminatorKind::Goto { target } => {
9191
self.check_bb(terminator.source_info.span, *target);
9292
}
93-
TerminatorKind::SwitchInt { targets, .. } => {
94-
if targets.is_empty() {
93+
TerminatorKind::SwitchInt { targets, values, .. } => {
94+
if targets.len() != values.len() + 1 {
9595
self.fail(
9696
terminator.source_info.span,
97-
"encountered `SwitchInt` terminator with no target to jump to",
97+
format!(
98+
"encountered `SwitchInt` terminator with {} values, but {} targets (should be values+1)",
99+
values.len(),
100+
targets.len(),
101+
),
98102
);
99103
}
100104
for target in targets {

0 commit comments

Comments
 (0)