auto merge of #8594 : bytewiseand/rust/static-fn-ptr, r=pcwalton
Fixes #8588
This commit is contained in:
commit
9feaf1d023
@ -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(*) => {
|
||||
|
14
src/test/auxiliary/static-function-pointer-aux.rs
Normal file
14
src/test/auxiliary/static-function-pointer-aux.rs
Normal 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;
|
26
src/test/run-pass/static-function-pointer-xc.rs
Normal file
26
src/test/run-pass/static-function-pointer-xc.rs
Normal 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);
|
||||
}
|
||||
}
|
24
src/test/run-pass/static-function-pointer.rs
Normal file
24
src/test/run-pass/static-function-pointer.rs
Normal 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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user