Skip to content

Commit 29b9966

Browse files
committed
Fix pointer consts to work with enums
1 parent 9ad616a commit 29b9966

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/librustc/middle/trans/consts.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,8 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
352352
}
353353
ast::expr_addr_of(ast::m_imm, sub) => {
354354
let cv = const_expr(cx, sub);
355-
let subty = ty::expr_ty(cx.tcx, sub),
356-
llty = type_of::type_of(cx, subty);
357355
let gv = do str::as_c_str("const") |name| {
358-
llvm::LLVMAddGlobal(cx.llmod, llty, name)
356+
llvm::LLVMAddGlobal(cx.llmod, val_ty(cv), name)
359357
};
360358
llvm::LLVMSetInitializer(gv, cv);
361359
llvm::LLVMSetGlobalConstant(gv, True);

src/test/run-pass/const-enum-ptr.rs

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, V1(int) }
12+
const C: &static/E = &V0;
13+
14+
fn main() {
15+
match *C {
16+
V0 => (),
17+
_ => die!()
18+
}
19+
}

0 commit comments

Comments
 (0)