auto merge of #4890 : jld/rust/enum-newtype-alignment, r=catamorphism

This commit is contained in:
bors 2013-02-18 10:02:48 -08:00
commit a2068f1b21
2 changed files with 29 additions and 3 deletions

View file

@ -328,11 +328,20 @@ pub fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
pub fn enum_body_types(cx: @crate_ctxt, did: ast::def_id, t: ty::t)
-> ~[TypeRef] {
let univar = ty::enum_is_univariant(cx.tcx, did);
let size = machine::static_size_of_enum(cx, t);
if !univar {
let size = machine::static_size_of_enum(cx, t);
~[T_enum_discrim(cx), T_array(T_i8(), size)]
} else {
~[T_array(T_i8(), size)]
}
else {
// Use the actual fields, so we get the alignment right.
match ty::get(t).sty {
ty::ty_enum(_, ref substs) => {
do ty::enum_variants(cx.tcx, did)[0].args.map |&field_ty| {
sizing_type_of(cx, ty::subst(cx.tcx, substs, field_ty))
}
}
_ => cx.sess.bug(~"enum is not an enum")
}
}
}

View file

@ -0,0 +1,17 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum E = u32;
struct S { a: u8, b: E }
const C: S = S { a: 0xA5, b: E(0xDEADBEEF) };
pub fn main() {
assert C.b == 0xDEADBEEF;
}