File tree 1 file changed +14
-5
lines changed
src/librustc/middle/trans
1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -394,13 +394,22 @@ pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
394
394
ast:: expr_path ( pth) => {
395
395
assert pth. types . len ( ) == 0 ;
396
396
match cx. tcx . def_map . find ( & e. id ) {
397
- Some ( ast:: def_fn( def_id, purity ) ) => {
397
+ Some ( ast:: def_fn( def_id, _purity ) ) => {
398
398
assert ast_util:: is_local ( def_id) ;
399
399
let f = base:: get_item_val ( cx, def_id. node ) ;
400
- match purity {
401
- ast:: extern_fn =>
402
- llvm:: LLVMConstPointerCast ( f, T_ptr ( T_i8 ( ) ) ) ,
403
- _ => C_struct ( ~[ f, C_null ( T_opaque_box_ptr ( cx) ) ] )
400
+ let ety = ty:: expr_ty_adjusted ( cx. tcx , e) ;
401
+ match ty:: get ( ety) . sty {
402
+ ty:: ty_bare_fn( * ) | ty:: ty_ptr( * ) => {
403
+ llvm:: LLVMConstPointerCast ( f, T_ptr ( T_i8 ( ) ) )
404
+ }
405
+ ty:: ty_closure( * ) => {
406
+ C_struct ( ~[ f, C_null ( T_opaque_box_ptr ( cx) ) ] )
407
+ }
408
+ _ => {
409
+ cx. sess . span_bug ( e. span , fmt ! (
410
+ "unexpected const fn type: %s" ,
411
+ ty_to_str( cx. tcx, ety) ) )
412
+ }
404
413
}
405
414
}
406
415
Some ( ast:: def_const( def_id) ) => {
You can’t perform that action at this time.
0 commit comments