auto merge of #12328 : nick29581/rust/abi, r=alexcrichton

This commit is contained in:
bors 2014-02-23 19:26:53 -08:00
commit 3c2650b4d5
19 changed files with 53 additions and 30 deletions

View File

@ -500,6 +500,7 @@ pub fn super_tys<C:Combine>(this: &C, a: ty::t, b: ty::t) -> cres<ty::t> {
(&ty::ty_trait(a_id, ref a_substs, a_store, a_mutbl, a_bounds),
&ty::ty_trait(b_id, ref b_substs, b_store, b_mutbl, b_bounds))
if a_id == b_id && a_mutbl == b_mutbl => {
debug!("Trying to match traits {:?} and {:?}", a, b);
let substs = if_ok!(this.substs(a_id, a_substs, b_substs));
let s = if_ok!(this.trait_stores(ty::terr_trait, a_store, b_store));
let bounds = if_ok!(this.bounds(a_bounds, b_bounds));

View File

@ -53,7 +53,7 @@ pub mod test;
pub static SCHEMA_VERSION: &'static str = "0.8.1";
type Pass = (&'static str, // name
extern fn(clean::Crate) -> plugins::PluginResult, // fn
fn(clean::Crate) -> plugins::PluginResult, // fn
&'static str); // description
static PASSES: &'static [Pass] = &[

View File

@ -15,7 +15,7 @@ use dl = std::unstable::dynamic_lib;
pub type PluginJson = Option<(~str, json::Json)>;
pub type PluginResult = (clean::Crate, PluginJson);
pub type PluginCallback = extern fn (clean::Crate) -> PluginResult;
pub type PluginCallback = fn (clean::Crate) -> PluginResult;
/// Manages loading and running of plugins
pub struct PluginManager {

View File

@ -862,11 +862,12 @@ impl Parser {
*/
let opt_abis = if self.eat_keyword(keywords::Extern) {
self.parse_opt_abis()
} else { None };
let abis = if self.eat_keyword(keywords::Extern) {
self.parse_opt_abis().unwrap_or(AbiSet::C())
} else {
AbiSet::Rust()
};
let abis = opt_abis.unwrap_or(AbiSet::Rust());
let purity = self.parse_unsafety();
self.expect_keyword(keywords::Fn);
let (decl, lifetimes) = self.parse_ty_fn_decl(true);

View File

@ -106,8 +106,8 @@ pub trait TDynBenchFn {
// may need to come up with a more clever definition of test in order
// to support isolation of tests into tasks.
pub enum TestFn {
StaticTestFn(extern fn()),
StaticBenchFn(extern fn(&mut BenchHarness)),
StaticTestFn(fn()),
StaticBenchFn(fn(&mut BenchHarness)),
StaticMetricFn(proc(&mut MetricMap)),
DynTestFn(proc()),
DynMetricFn(proc(&mut MetricMap)),

View File

@ -12,5 +12,5 @@
pub fn f(x: int) -> int { -x }
pub static F: extern fn(int) -> int = f;
pub static mut MutF: extern fn(int) -> int = f;
pub static F: fn(int) -> int = f;
pub static mut MutF: fn(int) -> int = f;

View File

@ -12,10 +12,10 @@
// other tycons.
fn main() {
fn f(f: extern fn(extern fn(extern fn()))) {
fn f(f: fn(fn(fn()))) {
}
fn g(f: extern fn(||)) {
fn g(f: fn(||)) {
}
f(g);

View File

@ -10,10 +10,10 @@
enum Either<T, U> { Left(T), Right(U) }
struct X(Either<(uint,uint),extern fn()>);
struct X(Either<(uint,uint), fn()>);
impl X {
pub fn with(&self, blk: |x: &Either<(uint,uint),extern fn()>|) {
pub fn with(&self, blk: |x: &Either<(uint,uint), fn()>|) {
let X(ref e) = *self;
blk(e)
}

View File

@ -16,7 +16,7 @@
*/
fn f() { }
static bare_fns: &'static [extern fn()] = &[f, f];
static bare_fns: &'static [fn()] = &[f, f];
struct S<'a>('a ||);
static closures: &'static [S<'static>] = &[S(f), S(f)];

View File

@ -0,0 +1,21 @@
// Copyright 2014 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.
// Ensure that declarations and types which use `extern fn` both have the same
// ABI (#9309).
extern {
fn printf();
}
pub fn main() {
// Will only type check if the type of _p and the decl of printf use the same ABI
let _p: extern unsafe fn() = printf;
}

View File

@ -13,7 +13,7 @@ fn f(i: int, called: &mut bool) {
*called = true;
}
fn g(f: extern fn(int, v: &mut bool), called: &mut bool) {
fn g(f: fn(int, v: &mut bool), called: &mut bool) {
f(10, called);
}

View File

@ -10,7 +10,7 @@
// This is what the signature to spawn should look like with bare functions
fn spawn<T:Send>(val: T, f: extern fn(T)) {
fn spawn<T:Send>(val: T, f: fn(T)) {
f(val);
}

View File

@ -11,7 +11,7 @@
fn foo(_f: extern fn(int) -> int) { }
fn foo(_f: fn(int) -> int) { }
fn id(x: int) -> int { return x; }

View File

@ -14,7 +14,7 @@
fn f() -> int { return 42; }
pub fn main() {
let g: extern fn() -> int = f;
let g: fn() -> int = f;
let i: int = g();
assert_eq!(i, 42);
}

View File

@ -14,13 +14,13 @@ fn mk() -> int { return 1; }
fn chk(a: int) { info!("{}", a); assert!((a == 1)); }
fn apply<T>(produce: extern fn() -> T,
consume: extern fn(T)) {
fn apply<T>(produce: fn() -> T,
consume: fn(T)) {
consume(produce());
}
pub fn main() {
let produce: extern fn() -> int = mk;
let consume: extern fn(v: int) = chk;
let produce: fn() -> int = mk;
let consume: fn(v: int) = chk;
apply::<int>(produce, consume);
}

View File

@ -10,7 +10,7 @@
struct mytype(Mytype);
struct Mytype {compute: extern fn(mytype) -> int, val: int}
struct Mytype {compute: fn(mytype) -> int, val: int}
fn compute(i: mytype) -> int {
let mytype(m) = i;

View File

@ -11,8 +11,8 @@
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;
static F: fn(int) -> int = f;
static mut G: fn(int) -> int = f;
pub fn main() {
assert_eq!(F(42), 42);

View File

@ -15,13 +15,13 @@ fn checktrue(rs: bool) -> bool { assert!((rs)); return true; }
pub fn main() { let k = checktrue; evenk(42, k); oddk(45, k); }
fn evenk(n: int, k: extern fn(bool) -> bool) -> bool {
fn evenk(n: int, k: fn(bool) -> bool) -> bool {
info!("evenk");
info!("{:?}", n);
if n == 0 { return k(true); } else { return oddk(n - 1, k); }
}
fn oddk(n: int, k: extern fn(bool) -> bool) -> bool {
fn oddk(n: int, k: fn(bool) -> bool) -> bool {
info!("oddk");
info!("{:?}", n);
if n == 0 { return k(false); } else { return evenk(n - 1, k); }

View File

@ -14,8 +14,8 @@ struct Foo(int);
struct Bar(int, int);
pub fn main() {
let f: extern fn(int) -> Foo = Foo;
let g: extern fn(int, int) -> Bar = Bar;
let f: fn(int) -> Foo = Foo;
let g: fn(int, int) -> Bar = Bar;
assert_eq!(f(42), Foo(42));
assert_eq!(g(4, 7), Bar(4, 7));
}