diff options
| author | Ralf Jung <post@ralfj.de> | 2020-05-31 15:07:16 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2020-05-31 15:07:16 +0200 |
| commit | 9a4bdbff9e52fe2bb2977ea6edddb13064726a25 (patch) | |
| tree | c479025b4ca42bf44b15199c4e209ebb6581aaf0 | |
| parent | e07e42433f9f8e2845d4941c59dc64918d467228 (diff) | |
| download | rust-9a4bdbff9e52fe2bb2977ea6edddb13064726a25.tar.gz rust-9a4bdbff9e52fe2bb2977ea6edddb13064726a25.zip | |
more checks for SwitchInt
| -rw-r--r-- | src/librustc_mir/transform/validate.rs | 10 |
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 { |
