about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJed Davis <jld@panix.com>2013-01-30 17:51:57 -0800
committerJed Davis <jld@panix.com>2013-02-07 18:31:12 -0800
commit30aae3d9102c42aacde454620247e5b99c5acfd2 (patch)
tree375c0f826229ae532e4271a699748763eef0d8e6
parentbbb1202528cf14de4f6b3a4f01c22ab19d64d8e7 (diff)
downloadrust-30aae3d9102c42aacde454620247e5b99c5acfd2.tar.gz
rust-30aae3d9102c42aacde454620247e5b99c5acfd2.zip
Fix const enum type issues for structs.
-rw-r--r--src/librustc/middle/trans/consts.rs3
-rw-r--r--src/test/run-pass/const-enum-struct.rs19
-rw-r--r--src/test/run-pass/const-enum-struct2.rs19
3 files changed, 39 insertions, 2 deletions
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 <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 { 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 <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 { 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;
+}