Skip to content

Commit 3bfd0c9

Browse files
committed
remove switch_ty reliance in codegen
1 parent 38bd83d commit 3bfd0c9

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/librustc_codegen_ssa/mir/block.rs

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
200200
targets: &Vec<mir::BasicBlock>,
201201
) {
202202
let discr = self.codegen_operand(&mut bx, &discr);
203+
// `switch_ty` is redundant, sanity-check that.
204+
assert_eq!(discr.layout.ty, switch_ty);
203205
if targets.len() == 2 {
204206
// If there are two targets, emit br instead of switch
205207
let lltrue = helper.llblock(self, targets[0]);

src/librustc_middle/mir/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,8 @@ pub enum TerminatorKind<'tcx> {
10751075
discr: Operand<'tcx>,
10761076

10771077
/// The type of value being tested.
1078+
/// This is always the same as the type of `discr`.
1079+
/// FIXME: remove this redundant information. Currently, it is relied on by pretty-printing.
10781080
switch_ty: Ty<'tcx>,
10791081

10801082
/// Possible values. The locations to branch to in each case

src/librustc_mir/interpret/terminator.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
2424

2525
Goto { target } => self.go_to_block(target),
2626

27-
SwitchInt { ref discr, ref values, ref targets, .. } => {
27+
SwitchInt { ref discr, ref values, ref targets, switch_ty } => {
2828
let discr = self.read_immediate(self.eval_operand(discr, None)?)?;
2929
trace!("SwitchInt({:?})", *discr);
30+
assert_eq!(discr.layout.ty, switch_ty);
3031

3132
// Branch to the `otherwise` case by default, if no match is found.
3233
assert!(!targets.is_empty());
@@ -55,7 +56,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
5556
ref args,
5657
destination,
5758
ref cleanup,
58-
from_hir_call: _from_hir_call,
59+
from_hir_call: _,
5960
fn_span: _,
6061
} => {
6162
let old_stack = self.frame_idx();

0 commit comments

Comments
 (0)