Skip to content

Commit 52ffeda

Browse files
committed
Fix type retrieval for Switch translation
Previously it would go through def_id and retrieve a type that’s not always correct, monomorphized, etc.
1 parent ac16d32 commit 52ffeda

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/librustc_trans/trans/mir/block.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
4848
}
4949

5050
mir::Terminator::Switch { ref discr, ref adt_def, ref targets } => {
51-
let adt_ty = bcx.tcx().lookup_item_type(adt_def.did).ty;
52-
let represented_ty = adt::represent_type(bcx.ccx(), adt_ty);
53-
5451
let discr_lvalue = self.trans_lvalue(bcx, discr);
55-
let discr = adt::trans_get_discr(bcx, &represented_ty, discr_lvalue.llval, None);
52+
let ty = discr_lvalue.ty.to_ty(bcx.tcx());
53+
let repr = adt::represent_type(bcx.ccx(), ty);
54+
let discr = adt::trans_get_discr(bcx, &repr, discr_lvalue.llval, None);
5655

5756
// The else branch of the Switch can't be hit, so branch to an unreachable
5857
// instruction so LLVM knows that
@@ -61,7 +60,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
6160
let switch = build::Switch(bcx, discr, unreachable_blk.llbb, targets.len());
6261
assert_eq!(adt_def.variants.len(), targets.len());
6362
for (adt_variant, target) in adt_def.variants.iter().zip(targets) {
64-
let llval = adt::trans_case(bcx, &*represented_ty, adt_variant.disr_val);
63+
let llval = adt::trans_case(bcx, &*repr, adt_variant.disr_val);
6564
let llbb = self.llblock(*target);
6665

6766
build::AddCase(switch, llval, llbb)

0 commit comments

Comments
 (0)