]> git.lizzy.rs Git - rust.git/commitdiff
All uses of `extern fn` should mean `extern "C" fn`. Closes #9309.
authorNick Cameron <ncameron@mozilla.com>
Fri, 14 Feb 2014 04:23:01 +0000 (17:23 +1300)
committerNick Cameron <ncameron@mozilla.com>
Mon, 24 Feb 2014 00:24:57 +0000 (13:24 +1300)
19 files changed:
src/librustc/middle/typeck/infer/combine.rs
src/librustdoc/lib.rs
src/librustdoc/plugins.rs
src/libsyntax/parse/parser.rs
src/libtest/lib.rs
src/test/auxiliary/static-function-pointer-aux.rs
src/test/compile-fail/block-coerce-no-2.rs
src/test/compile-fail/borrowck-autoref-3261.rs
src/test/run-pass/const-vec-of-fns.rs
src/test/run-pass/fn-abi.rs [new file with mode: 0644]
src/test/run-pass/fn-bare-assign.rs
src/test/run-pass/fn-bare-spawn.rs
src/test/run-pass/fn-lval.rs
src/test/run-pass/fun-indirect-call.rs
src/test/run-pass/generic-temporary.rs
src/test/run-pass/newtype.rs
src/test/run-pass/static-function-pointer.rs
src/test/run-pass/tail-cps.rs
src/test/run-pass/tuple-struct-constructor-pointer.rs

index eb45065952da3f404a492b0057c897cef761ba58..95d605823da3e450d83051f30f17d27dc4c4b41a 100644 (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));
index 4fb71b6710ea3f219c62f3bf1b4a60f35f98d8fc..51edf4fdff43c78c3883a6b4472fa7db208613e0 100644 (file)
@@ -53,7 +53,7 @@ pub mod html {
 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] = &[
index 3a6ea6725071406d986bfd1953e8f6f9e7e443f6..db714376646b51704014738c79d6e2dc421e297d 100644 (file)
@@ -15,7 +15,7 @@
 
 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 {
index fed2034cd26ae6ae8e8603db88e901bb5a9714c3..60c43632ba04640df49ba7eeaa14a439768a16b7 100644 (file)
@@ -862,11 +862,12 @@ pub fn parse_ty_bare_fn(&mut self) -> Ty_ {
 
         */
 
-        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);
index eba922ac7b8b96ec9b28131fad7767733d3d3308..8e39230a36a6207e2547e30a4c059628dca32ee7 100644 (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)),
index b257f4578a5ff20e0bfc6a5dd7546ae67cfb8b0c..b2e6548890da53351d249465ba341cf2c72ff60c 100644 (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;
index 52359bed59c90438db721632d7da2cfbee3c0908..e268b0e93fdad4e9aac45a114c0adeb738d51b28 100644 (file)
 // 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);
index 29016a2f44f14921b9f94ab318ff6e7da54634b8..2a2a3dee1dfa6724cb9462dfc9807c3ebc0788ce 100644 (file)
 
 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)
     }
index 45ba9f1cab5e3d241876a1a6c6b8217049464076..6d193ec400ba73925862bc3867481e080662d8fc 100644 (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)];
 
diff --git a/src/test/run-pass/fn-abi.rs b/src/test/run-pass/fn-abi.rs
new file mode 100644 (file)
index 0000000..7d7c1a5
--- /dev/null
@@ -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;
+}
index 7c8fbd2989f765a1133dea06c7192811d56779d9..fd8721e29e9b83767d605418f13ef14837af601e 100644 (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);
 }
 
index e9954be93575ca21eb346a5688fcfd94b77ebf03..4fc2c69ceb34f3dfaa37ae78999f08d09a279935 100644 (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);
 }
 
index 4a81d8f0ece1de408b1b6a8eb93085e74e642d81..f21dbc6f987d21818962c88cce30d9680f37ed00 100644 (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; }
 
index 72383104b3c41750861011a4dad4435d64741b87..4bff06f2a03825f5f87bf8981930f8c1af736c0b 100644 (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);
 }
index eca325a50f99c35ba97b858011b28157e2bbac95..f2dbc5a0d319a5a679302df43a0fada2436014be 100644 (file)
 
 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);
 }
index b0d2da9773c500f1cc2d5592c882d57f6a591027..0d1103086ae790729bc45caba8d8d678b1b8c7c2 100644 (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;
index f8a889113ac5c2eb70d1fa016bcab16542c6860e..ff1091e07ef169ebcdb1d19363e3fbfdaf06be6c 100644 (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);
index d0ba12bec1c908c753afc69e5f4df6134f4c6244..05b3f98ea08cd27244c325a18ea4dc3f8abcae82 100644 (file)
 
 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); }
index e51e6ffd52abc0f009b53e081ac2426f2415d32f..097fdbf699bfa2753f8570a5ae00a982670dea3a 100644 (file)
@@ -14,8 +14,8 @@
 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));
 }