Skip to content

Commit

Permalink
auto merge of #12328 : nick29581/rust/abi, r=alexcrichton
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Feb 24, 2014
2 parents 7cc6b5e + 317a253 commit 3c2650b
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/librustc/middle/typeck/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] = &[
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
4 changes: 2 additions & 2 deletions src/test/auxiliary/static-function-pointer-aux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions src/test/compile-fail/block-coerce-no-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/borrowck-autoref-3261.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/const-vec-of-fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)];

Expand Down
21 changes: 21 additions & 0 deletions src/test/run-pass/fn-abi.rs
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion src/test/run-pass/fn-bare-assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/fn-bare-spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/fn-lval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@



fn foo(_f: extern fn(int) -> int) { }
fn foo(_f: fn(int) -> int) { }

fn id(x: int) -> int { return x; }

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/fun-indirect-call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
8 changes: 4 additions & 4 deletions src/test/run-pass/generic-temporary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/test/run-pass/newtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/static-function-pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/tail-cps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/tuple-struct-constructor-pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit 3c2650b

Please sign in to comment.