Skip to content

Commit 27a1834

Browse files
committed
Auto merge of #30588 - nagisa:mir-unit-enums-again, r=eddyb
A dumb mistake on my part from previous PR fixing unit enums in MIR.
2 parents 8975307 + e7cab13 commit 27a1834

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/librustc_trans/trans/mir/rvalue.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
102102
mir::AggregateKind::Adt(adt_def, index, _)
103103
if adt_def.variants[index].kind() == ty::VariantKind::Unit => {
104104
let repr = adt::represent_type(bcx.ccx(), dest.ty.to_ty(bcx.tcx()));
105-
adt::trans_set_discr(bcx, &*repr, dest.llval, 0);
105+
let disr = adt_def.variants[index].disr_val;
106+
adt::trans_set_discr(bcx, &*repr, dest.llval, disr);
106107
},
107108
_ => {
108109
for (i, operand) in operands.iter().enumerate() {

src/test/run-pass/mir_refs_correct.rs

+12
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ enum E {
5959
U(u8)
6060
}
6161

62+
#[derive(PartialEq, Debug, Eq)]
63+
enum CEnum {
64+
A = 0x321,
65+
B = 0x123
66+
}
67+
6268
const C: u8 = 84;
6369
const C2: [u8; 5] = [42; 5];
6470
const C3: [u8; 3] = [42, 41, 40];
@@ -187,6 +193,11 @@ fn t22() -> Option<u8> {
187193
None
188194
}
189195

196+
#[rustc_mir]
197+
fn t23() -> (CEnum, CEnum) {
198+
(CEnum::A, CEnum::B)
199+
}
200+
190201
fn main(){
191202
unsafe {
192203
assert_eq!(t1()(), regular());
@@ -228,5 +239,6 @@ fn main(){
228239
assert_eq!(t20()(123u64, 38u32), <u32 as T<_, _>>::staticmeth(123, 38));
229240
assert_eq!(t21(), Unit);
230241
assert_eq!(t22(), None);
242+
assert_eq!(t23(), (CEnum::A, CEnum::B));
231243
}
232244
}

0 commit comments

Comments
 (0)