From 317a253b22a512fad46c3749ea86d9674ff18453 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 14 Feb 2014 17:23:01 +1300 Subject: [PATCH] All uses of `extern fn` should mean `extern "C" fn`. Closes #9309. --- src/librustc/middle/typeck/infer/combine.rs | 1 + src/librustdoc/lib.rs | 2 +- src/librustdoc/plugins.rs | 2 +- src/libsyntax/parse/parser.rs | 9 ++++---- src/libtest/lib.rs | 4 ++-- .../auxiliary/static-function-pointer-aux.rs | 4 ++-- src/test/compile-fail/block-coerce-no-2.rs | 4 ++-- .../compile-fail/borrowck-autoref-3261.rs | 4 ++-- src/test/run-pass/const-vec-of-fns.rs | 2 +- src/test/run-pass/fn-abi.rs | 21 +++++++++++++++++++ src/test/run-pass/fn-bare-assign.rs | 2 +- src/test/run-pass/fn-bare-spawn.rs | 2 +- src/test/run-pass/fn-lval.rs | 2 +- src/test/run-pass/fun-indirect-call.rs | 2 +- src/test/run-pass/generic-temporary.rs | 8 +++---- src/test/run-pass/newtype.rs | 2 +- src/test/run-pass/static-function-pointer.rs | 4 ++-- src/test/run-pass/tail-cps.rs | 4 ++-- .../tuple-struct-constructor-pointer.rs | 4 ++-- 19 files changed, 53 insertions(+), 30 deletions(-) create mode 100644 src/test/run-pass/fn-abi.rs diff --git a/src/librustc/middle/typeck/infer/combine.rs b/src/librustc/middle/typeck/infer/combine.rs index eb45065952d..95d605823da 100644 --- a/src/librustc/middle/typeck/infer/combine.rs +++ b/src/librustc/middle/typeck/infer/combine.rs @@ -500,6 +500,7 @@ pub fn super_tys(this: &C, a: ty::t, b: ty::t) -> cres { (&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)); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 4fb71b6710e..51edf4fdff4 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -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] = &[ diff --git a/src/librustdoc/plugins.rs b/src/librustdoc/plugins.rs index 3a6ea672507..db714376646 100644 --- a/src/librustdoc/plugins.rs +++ b/src/librustdoc/plugins.rs @@ -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 { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index fed2034cd26..60c43632ba0 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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); diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index eba922ac7b8..8e39230a36a 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -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)), diff --git a/src/test/auxiliary/static-function-pointer-aux.rs b/src/test/auxiliary/static-function-pointer-aux.rs index b257f4578a5..b2e6548890d 100644 --- a/src/test/auxiliary/static-function-pointer-aux.rs +++ b/src/test/auxiliary/static-function-pointer-aux.rs @@ -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; diff --git a/src/test/compile-fail/block-coerce-no-2.rs b/src/test/compile-fail/block-coerce-no-2.rs index 52359bed59c..e268b0e93fd 100644 --- a/src/test/compile-fail/block-coerce-no-2.rs +++ b/src/test/compile-fail/block-coerce-no-2.rs @@ -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); diff --git a/src/test/compile-fail/borrowck-autoref-3261.rs b/src/test/compile-fail/borrowck-autoref-3261.rs index 29016a2f44f..2a2a3dee1df 100644 --- a/src/test/compile-fail/borrowck-autoref-3261.rs +++ b/src/test/compile-fail/borrowck-autoref-3261.rs @@ -10,10 +10,10 @@ enum Either { 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) } diff --git a/src/test/run-pass/const-vec-of-fns.rs b/src/test/run-pass/const-vec-of-fns.rs index 45ba9f1cab5..6d193ec400b 100644 --- a/src/test/run-pass/const-vec-of-fns.rs +++ b/src/test/run-pass/const-vec-of-fns.rs @@ -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)]; diff --git a/src/test/run-pass/fn-abi.rs b/src/test/run-pass/fn-abi.rs new file mode 100644 index 00000000000..7d7c1a56030 --- /dev/null +++ b/src/test/run-pass/fn-abi.rs @@ -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 or the MIT license +// , 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; +} diff --git a/src/test/run-pass/fn-bare-assign.rs b/src/test/run-pass/fn-bare-assign.rs index 7c8fbd2989f..fd8721e29e9 100644 --- a/src/test/run-pass/fn-bare-assign.rs +++ b/src/test/run-pass/fn-bare-assign.rs @@ -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); } diff --git a/src/test/run-pass/fn-bare-spawn.rs b/src/test/run-pass/fn-bare-spawn.rs index e9954be9357..4fc2c69ceb3 100644 --- a/src/test/run-pass/fn-bare-spawn.rs +++ b/src/test/run-pass/fn-bare-spawn.rs @@ -10,7 +10,7 @@ // This is what the signature to spawn should look like with bare functions -fn spawn(val: T, f: extern fn(T)) { +fn spawn(val: T, f: fn(T)) { f(val); } diff --git a/src/test/run-pass/fn-lval.rs b/src/test/run-pass/fn-lval.rs index 4a81d8f0ece..f21dbc6f987 100644 --- a/src/test/run-pass/fn-lval.rs +++ b/src/test/run-pass/fn-lval.rs @@ -11,7 +11,7 @@ -fn foo(_f: extern fn(int) -> int) { } +fn foo(_f: fn(int) -> int) { } fn id(x: int) -> int { return x; } diff --git a/src/test/run-pass/fun-indirect-call.rs b/src/test/run-pass/fun-indirect-call.rs index 72383104b3c..4bff06f2a03 100644 --- a/src/test/run-pass/fun-indirect-call.rs +++ b/src/test/run-pass/fun-indirect-call.rs @@ -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); } diff --git a/src/test/run-pass/generic-temporary.rs b/src/test/run-pass/generic-temporary.rs index eca325a50f9..f2dbc5a0d31 100644 --- a/src/test/run-pass/generic-temporary.rs +++ b/src/test/run-pass/generic-temporary.rs @@ -14,13 +14,13 @@ fn mk() -> int { return 1; } fn chk(a: int) { info!("{}", a); assert!((a == 1)); } -fn apply(produce: extern fn() -> T, - consume: extern fn(T)) { +fn apply(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::(produce, consume); } diff --git a/src/test/run-pass/newtype.rs b/src/test/run-pass/newtype.rs index b0d2da9773c..0d1103086ae 100644 --- a/src/test/run-pass/newtype.rs +++ b/src/test/run-pass/newtype.rs @@ -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; diff --git a/src/test/run-pass/static-function-pointer.rs b/src/test/run-pass/static-function-pointer.rs index f8a889113ac..ff1091e07ef 100644 --- a/src/test/run-pass/static-function-pointer.rs +++ b/src/test/run-pass/static-function-pointer.rs @@ -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); diff --git a/src/test/run-pass/tail-cps.rs b/src/test/run-pass/tail-cps.rs index d0ba12bec1c..05b3f98ea08 100644 --- a/src/test/run-pass/tail-cps.rs +++ b/src/test/run-pass/tail-cps.rs @@ -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); } diff --git a/src/test/run-pass/tuple-struct-constructor-pointer.rs b/src/test/run-pass/tuple-struct-constructor-pointer.rs index e51e6ffd52a..097fdbf699b 100644 --- a/src/test/run-pass/tuple-struct-constructor-pointer.rs +++ b/src/test/run-pass/tuple-struct-constructor-pointer.rs @@ -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)); }