Skip to content

Commit

Permalink
MIR validation: check switch_ty
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Jun 21, 2020
1 parent 3bfd0c9 commit 6297228
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/librustc_mir/transform/validate.rs
Expand Up @@ -121,7 +121,18 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
TerminatorKind::Goto { target } => {
self.check_edge(location, *target, EdgeKind::Normal);
}
TerminatorKind::SwitchInt { targets, values, .. } => {
TerminatorKind::SwitchInt { targets, values, switch_ty, discr } => {
let ty = discr.ty(&self.body.local_decls, self.tcx);
if ty != *switch_ty {
self.fail(
location,
format!(
"encountered `SwitchInt` terminator with type mismatch: {:?} != {:?}",
ty,
switch_ty,
),
);
}
if targets.len() != values.len() + 1 {
self.fail(
location,
Expand Down

0 comments on commit 6297228

Please sign in to comment.