From 52ffeda8c833ac97f7c57b239acc30c683fb5391 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Thu, 14 Jan 2016 03:22:02 +0200 Subject: [PATCH] Fix type retrieval for Switch translation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously it would go through def_id and retrieve a type that’s not always correct, monomorphized, etc. --- src/librustc_trans/trans/mir/block.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/librustc_trans/trans/mir/block.rs b/src/librustc_trans/trans/mir/block.rs index 18a9aad0e915..ad5b0069a48d 100644 --- a/src/librustc_trans/trans/mir/block.rs +++ b/src/librustc_trans/trans/mir/block.rs @@ -48,11 +48,10 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { } mir::Terminator::Switch { ref discr, ref adt_def, ref targets } => { - let adt_ty = bcx.tcx().lookup_item_type(adt_def.did).ty; - let represented_ty = adt::represent_type(bcx.ccx(), adt_ty); - let discr_lvalue = self.trans_lvalue(bcx, discr); - let discr = adt::trans_get_discr(bcx, &represented_ty, discr_lvalue.llval, None); + let ty = discr_lvalue.ty.to_ty(bcx.tcx()); + let repr = adt::represent_type(bcx.ccx(), ty); + let discr = adt::trans_get_discr(bcx, &repr, discr_lvalue.llval, None); // The else branch of the Switch can't be hit, so branch to an unreachable // instruction so LLVM knows that @@ -61,7 +60,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { let switch = build::Switch(bcx, discr, unreachable_blk.llbb, targets.len()); assert_eq!(adt_def.variants.len(), targets.len()); for (adt_variant, target) in adt_def.variants.iter().zip(targets) { - let llval = adt::trans_case(bcx, &*represented_ty, adt_variant.disr_val); + let llval = adt::trans_case(bcx, &*repr, adt_variant.disr_val); let llbb = self.llblock(*target); build::AddCase(switch, llval, llbb)