Skip to content

Commit 30aae3d

Browse files
committed
Fix const enum type issues for structs.
1 parent bbb1202 commit 30aae3d

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/librustc/middle/trans/consts.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
381381
}
382382
})
383383
};
384-
let llty = type_of::type_of(cx, ety);
385-
C_named_struct(llty, [C_struct(cs)])
384+
C_struct([C_struct(cs)])
386385
}
387386
ast::expr_vec(es, ast::m_imm) => {
388387
let (v, _, _) = const_vec(cx, e, es);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum E { V16(u16), V32(u32) }
12+
struct S { a: E, b: u16, c: u16 }
13+
const C: S = S { a: V16(0xDEAD), b: 0x600D, c: 0xBAD };
14+
15+
fn main() {
16+
let n = C.b;
17+
assert n != 0xBAD;
18+
assert n == 0x600D;
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum E { V0, V16(u16) }
12+
struct S { a: E, b: u16, c: u16 }
13+
const C: S = S { a: V0, b: 0x600D, c: 0xBAD };
14+
15+
fn main() {
16+
let n = C.b;
17+
assert n != 0xBAD;
18+
assert n == 0x600D;
19+
}

0 commit comments

Comments
 (0)