Fix const enum type issues for structs.
This commit is contained in:
parent
bbb1202528
commit
30aae3d910
@ -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);
|
||||
|
19
src/test/run-pass/const-enum-struct.rs
Normal file
19
src/test/run-pass/const-enum-struct.rs
Normal 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;
|
||||
}
|
19
src/test/run-pass/const-enum-struct2.rs
Normal file
19
src/test/run-pass/const-enum-struct2.rs
Normal 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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user