about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJed Davis <jld@panix.com>2013-03-03 14:53:15 -0800
committerJed Davis <jld@panix.com>2013-03-03 16:40:41 -0800
commit5f0a123f0d1c8718b015c973b3780bc9353e9159 (patch)
treec711c19a4ec1839b31f41728e42f80d18af93652 /src
parenta7de81ac3e559dcddfa9652d83457341a534a74d (diff)
Construct const fns based on the type, not the definition.
Otherwise we can add a null environment when we shouldn't.

Fixes #5210.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/trans/consts.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs
index 36cda3dfbe9..3cfafde1043 100644
--- a/src/librustc/middle/trans/consts.rs
+++ b/src/librustc/middle/trans/consts.rs
@@ -394,13 +394,22 @@ pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
           ast::expr_path(pth) => {
             assert pth.types.len() == 0;
             match cx.tcx.def_map.find(&e.id) {
-                Some(ast::def_fn(def_id, purity)) => {
+                Some(ast::def_fn(def_id, _purity)) => {
                     assert ast_util::is_local(def_id);
                     let f = base::get_item_val(cx, def_id.node);
-                    match purity {
-                      ast::extern_fn =>
-                        llvm::LLVMConstPointerCast(f, T_ptr(T_i8())),
-                      _ => C_struct(~[f, C_null(T_opaque_box_ptr(cx))])
+                    let ety = ty::expr_ty_adjusted(cx.tcx, e);
+                    match ty::get(ety).sty {
+                        ty::ty_bare_fn(*) | ty::ty_ptr(*) => {
+                            llvm::LLVMConstPointerCast(f, T_ptr(T_i8()))
+                        }
+                        ty::ty_closure(*) => {
+                            C_struct(~[f, C_null(T_opaque_box_ptr(cx))])
+                        }
+                        _ => {
+                            cx.sess.span_bug(e.span, fmt!(
+                                "unexpected const fn type: %s",
+                                ty_to_str(cx.tcx, ety)))
+                        }
                     }
                 }
                 Some(ast::def_const(def_id)) => {