Skip to content

Commit

Permalink
[MIR] Fix setting discriminant for unit enums
Browse files Browse the repository at this point in the history
  • Loading branch information
nagisa committed Dec 28, 2015
1 parent 8975307 commit e7cab13
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/librustc_trans/trans/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
mir::AggregateKind::Adt(adt_def, index, _)
if adt_def.variants[index].kind() == ty::VariantKind::Unit => {
let repr = adt::represent_type(bcx.ccx(), dest.ty.to_ty(bcx.tcx()));
adt::trans_set_discr(bcx, &*repr, dest.llval, 0);
let disr = adt_def.variants[index].disr_val;
adt::trans_set_discr(bcx, &*repr, dest.llval, disr);
},
_ => {
for (i, operand) in operands.iter().enumerate() {
Expand Down
12 changes: 12 additions & 0 deletions src/test/run-pass/mir_refs_correct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ enum E {
U(u8)
}

#[derive(PartialEq, Debug, Eq)]
enum CEnum {
A = 0x321,
B = 0x123
}

const C: u8 = 84;
const C2: [u8; 5] = [42; 5];
const C3: [u8; 3] = [42, 41, 40];
Expand Down Expand Up @@ -187,6 +193,11 @@ fn t22() -> Option<u8> {
None
}

#[rustc_mir]
fn t23() -> (CEnum, CEnum) {
(CEnum::A, CEnum::B)
}

fn main(){
unsafe {
assert_eq!(t1()(), regular());
Expand Down Expand Up @@ -228,5 +239,6 @@ fn main(){
assert_eq!(t20()(123u64, 38u32), <u32 as T<_, _>>::staticmeth(123, 38));
assert_eq!(t21(), Unit);
assert_eq!(t22(), None);
assert_eq!(t23(), (CEnum::A, CEnum::B));
}
}

0 comments on commit e7cab13

Please sign in to comment.