Fix const enum type issues for structs.

This commit is contained in:
Jed Davis 2013-01-30 17:51:57 -08:00
parent bbb1202528
commit 30aae3d910
3 changed files with 39 additions and 2 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}