diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 2f6011e3f65..0176e5ab320 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -459,14 +459,12 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { ast::expr_call(callee, args, _) => { match cx.tcx.def_map.find(&callee.id) { Some(ast::def_struct(def_id)) => { - let ety = ty::expr_ty(cx.tcx, e); - let llty = type_of::type_of(cx, ety); let llstructbody = C_struct(args.map(|a| const_expr(cx, *a))); if ty::ty_dtor(cx.tcx, def_id).is_present() { - C_named_struct(llty, ~[ llstructbody, C_u8(0) ]) + C_struct(~[ llstructbody, C_u8(0) ]) } else { - C_named_struct(llty, ~[ llstructbody ]) + C_struct(~[ llstructbody ]) } } Some(ast::def_variant(tid, vid)) => { diff --git a/src/test/run-pass/const-enum-tuplestruct.rs b/src/test/run-pass/const-enum-tuplestruct.rs new file mode 100644 index 00000000000..d9194ff26b1 --- /dev/null +++ b/src/test/run-pass/const-enum-tuplestruct.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(E, u16, u16); +const C: S = S(V16(0xDEAD), 0x600D, 0xBAD); + +fn main() { + let S(_, n, _) = C; + assert n != 0xBAD; + assert n == 0x600D; +} diff --git a/src/test/run-pass/const-enum-tuplestruct2.rs b/src/test/run-pass/const-enum-tuplestruct2.rs new file mode 100644 index 00000000000..b6d9d01479e --- /dev/null +++ b/src/test/run-pass/const-enum-tuplestruct2.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(E, u16, u16); +const C: S = S(V0, 0x600D, 0xBAD); + +fn main() { + let S(_, n, _) = C; + assert n != 0xBAD; + assert n == 0x600D; +}