]> git.lizzy.rs Git - rust.git/commitdiff
more checks for SwitchInt
authorRalf Jung <post@ralfj.de>
Sun, 31 May 2020 13:07:16 +0000 (15:07 +0200)
committerRalf Jung <post@ralfj.de>
Sun, 31 May 2020 13:07:16 +0000 (15:07 +0200)
src/librustc_mir/transform/validate.rs

index 7a1393468cec67da859b5c67a8b1ae9111b76274..4039d1b50e8f577ddc6b0c7245c11e528a091173 100644 (file)
@@ -90,11 +90,15 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, _location: Locatio
             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 {