@@ -269,10 +269,15 @@ pub fn trans_const(ccx: @CrateContext, r: &Repr, discr: int,
269
269
assert min <= discr && discr <= max;
270
270
C_int ( ccx, discr)
271
271
}
272
- Univariant ( ref st, _dt ) => {
272
+ Univariant ( ref st, dt ) => {
273
273
assert discr == 0 ;
274
- // consts are never destroyed, so the dtor flag is not needed
275
- C_struct ( build_const_struct ( ccx, st, vals) )
274
+ let s = C_struct ( build_const_struct ( ccx, st, vals) ) ;
275
+ match dt {
276
+ NoDtor => s,
277
+ // The actual destructor flag doesn't need to be present.
278
+ // But add an extra struct layer for compatibility.
279
+ DtorPresent | DtorAbsent => C_struct ( ~[ s] )
280
+ }
276
281
}
277
282
General ( ref cases) => {
278
283
let case = & cases[ discr as uint ] ;
@@ -336,7 +341,9 @@ pub fn const_get_element(ccx: @CrateContext, r: &Repr, val: ValueRef,
336
341
match * r {
337
342
Unit ( * ) | CEnum ( * ) => ccx. sess . bug ( ~"element access in C -like enum \
338
343
const ") ,
339
- Univariant ( * ) => const_struct_field ( ccx, val, ix) ,
344
+ Univariant ( _, NoDtor ) => const_struct_field ( ccx, val, ix) ,
345
+ Univariant ( * ) => const_struct_field ( ccx, const_get_elt ( ccx, val,
346
+ [ 0 ] ) , ix) ,
340
347
General ( * ) => const_struct_field ( ccx, const_get_elt ( ccx, val,
341
348
[ 1 , 0 ] ) , ix)
342
349
}
0 commit comments