about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-05-31 15:07:16 +0200
committerRalf Jung <post@ralfj.de>2020-05-31 15:07:16 +0200
commit9a4bdbff9e52fe2bb2977ea6edddb13064726a25 (patch)
treec479025b4ca42bf44b15199c4e209ebb6581aaf0
parente07e42433f9f8e2845d4941c59dc64918d467228 (diff)
downloadrust-9a4bdbff9e52fe2bb2977ea6edddb13064726a25.tar.gz
rust-9a4bdbff9e52fe2bb2977ea6edddb13064726a25.zip
more checks for SwitchInt
-rw-r--r--src/librustc_mir/transform/validate.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/librustc_mir/transform/validate.rs b/src/librustc_mir/transform/validate.rs
index 7a1393468ce..4039d1b50e8 100644
--- a/src/librustc_mir/transform/validate.rs
+++ b/src/librustc_mir/transform/validate.rs
@@ -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 {