diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 39fcdf405bc..2f6011e3f65 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -381,8 +381,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { } }) }; - let llty = type_of::type_of(cx, ety); - C_named_struct(llty, [C_struct(cs)]) + C_struct([C_struct(cs)]) } ast::expr_vec(es, ast::m_imm) => { let (v, _, _) = const_vec(cx, e, es); diff --git a/src/test/run-pass/const-enum-struct.rs b/src/test/run-pass/const-enum-struct.rs new file mode 100644 index 00000000000..463b8452bb8 --- /dev/null +++ b/src/test/run-pass/const-enum-struct.rs @@ -0,0 +1,19 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum E { V16(u16), V32(u32) } +struct S { a: E, b: u16, c: u16 } +const C: S = S { a: V16(0xDEAD), b: 0x600D, c: 0xBAD }; + +fn main() { + let n = C.b; + assert n != 0xBAD; + assert n == 0x600D; +} diff --git a/src/test/run-pass/const-enum-struct2.rs b/src/test/run-pass/const-enum-struct2.rs new file mode 100644 index 00000000000..f3454932678 --- /dev/null +++ b/src/test/run-pass/const-enum-struct2.rs @@ -0,0 +1,19 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum E { V0, V16(u16) } +struct S { a: E, b: u16, c: u16 } +const C: S = S { a: V0, b: 0x600D, c: 0xBAD }; + +fn main() { + let n = C.b; + assert n != 0xBAD; + assert n == 0x600D; +}