Skip to content

Commit 6297228

Browse files
committed
MIR validation: check switch_ty
1 parent 3bfd0c9 commit 6297228

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/librustc_mir/transform/validate.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,18 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
121121
TerminatorKind::Goto { target } => {
122122
self.check_edge(location, *target, EdgeKind::Normal);
123123
}
124-
TerminatorKind::SwitchInt { targets, values, .. } => {
124+
TerminatorKind::SwitchInt { targets, values, switch_ty, discr } => {
125+
let ty = discr.ty(&self.body.local_decls, self.tcx);
126+
if ty != *switch_ty {
127+
self.fail(
128+
location,
129+
format!(
130+
"encountered `SwitchInt` terminator with type mismatch: {:?} != {:?}",
131+
ty,
132+
switch_ty,
133+
),
134+
);
135+
}
125136
if targets.len() != values.len() + 1 {
126137
self.fail(
127138
location,

0 commit comments

Comments
 (0)