auto merge of #8594 : bytewiseand/rust/static-fn-ptr, r=pcwalton

Fixes #8588
This commit is contained in:
bors 2013-08-21 15:51:34 -07:00
commit 9feaf1d023
4 changed files with 66 additions and 1 deletions

View File

@ -135,6 +135,7 @@ pub fn trans(bcx: @mut Block, expr: @ast::expr) -> Callee {
ast::def_struct(def_id) => {
fn_callee(bcx, trans_fn_ref(bcx, def_id, ref_expr.id))
}
ast::def_static(*) |
ast::def_arg(*) |
ast::def_local(*) |
ast::def_binding(*) |
@ -143,7 +144,7 @@ pub fn trans(bcx: @mut Block, expr: @ast::expr) -> Callee {
datum_callee(bcx, ref_expr)
}
ast::def_mod(*) | ast::def_foreign_mod(*) | ast::def_trait(*) |
ast::def_static(*) | ast::def_ty(*) | ast::def_prim_ty(*) |
ast::def_ty(*) | ast::def_prim_ty(*) |
ast::def_use(*) | ast::def_typaram_binder(*) |
ast::def_region(*) | ast::def_label(*) | ast::def_ty_param(*) |
ast::def_self_ty(*) | ast::def_method(*) => {

View File

@ -0,0 +1,14 @@
// 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.
pub fn f(x: int) -> int { -x }
pub static F: extern fn(int) -> int = f;
pub static mut MutF: extern fn(int) -> int = f;

View File

@ -0,0 +1,26 @@
// 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.
// xfail-fast
// aux-build:static-function-pointer-aux.rs
extern mod aux(name = "static-function-pointer-aux");
fn f(x: int) -> int { x }
fn main() {
assert_eq!(aux::F(42), -42);
unsafe {
assert_eq!(aux::MutF(42), -42);
aux::MutF = f;
assert_eq!(aux::MutF(42), 42);
aux::MutF = aux::f;
assert_eq!(aux::MutF(42), -42);
}
}

View File

@ -0,0 +1,24 @@
// 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.
fn f(x: int) -> int { x }
fn g(x: int) -> int { 2 * x }
static F: extern fn(int) -> int = f;
static mut G: extern fn(int) -> int = f;
pub fn main() {
assert_eq!(F(42), 42);
unsafe {
assert_eq!(G(42), 42);
G = g;
assert_eq!(G(42), 84);
}
}