about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-12-04 08:52:47 +0000
committerbors <bors@rust-lang.org>2014-12-04 08:52:47 +0000
commit53e8bd641a4d3495fb4ffb12e732390d9b4ff93e (patch)
tree06bb72cfc78e0956825adc0c3de2d9c7b5d8c19c /src/libcore
parent3c89031e1f213030f0514c8dcb9e6fa19ddbd323 (diff)
parentf2731ffb52a5873800df4ef2dfa28da9c4302976 (diff)
downloadrust-53e8bd641a4d3495fb4ffb12e732390d9b4ff93e.tar.gz
rust-53e8bd641a4d3495fb4ffb12e732390d9b4ff93e.zip
auto merge of #19449 : nikomatsakis/rust/unboxed-closure-fn-impl, r=pcwalton
Implement the `Fn` trait for bare fn pointers in the compiler rather
than doing it using hard-coded impls. This means that it works also
for more complex fn types involving bound regions.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/ops.rs80
1 files changed, 42 insertions, 38 deletions
diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs
index d85481098e4..4f4ec486797 100644
--- a/src/libcore/ops.rs
+++ b/src/libcore/ops.rs
@@ -833,48 +833,52 @@ impl<F,A,R> FnOnce<A,R> for F
     }
 }
 
-
-impl<Result> Fn<(),Result> for extern "Rust" fn() -> Result {
-    #[allow(non_snake_case)]
-    extern "rust-call" fn call(&self, _args: ()) -> Result {
-        (*self)()
+#[cfg(stage0)]
+mod fn_impls {
+    use super::Fn;
+
+    impl<Result> Fn<(),Result> for extern "Rust" fn() -> Result {
+        #[allow(non_snake_case)]
+        extern "rust-call" fn call(&self, _args: ()) -> Result {
+            (*self)()
+        }
     }
-}
 
-impl<Result,A0> Fn<(A0,),Result> for extern "Rust" fn(A0) -> Result {
-    #[allow(non_snake_case)]
-    extern "rust-call" fn call(&self, args: (A0,)) -> Result {
-        let (a0,) = args;
-        (*self)(a0)
+    impl<Result,A0> Fn<(A0,),Result> for extern "Rust" fn(A0) -> Result {
+        #[allow(non_snake_case)]
+        extern "rust-call" fn call(&self, args: (A0,)) -> Result {
+            let (a0,) = args;
+            (*self)(a0)
+        }
     }
-}
 
-macro_rules! def_fn(
-    ($($args:ident)*) => (
-        impl<Result$(,$args)*>
-        Fn<($($args,)*),Result>
-        for extern "Rust" fn($($args: $args,)*) -> Result {
-            #[allow(non_snake_case)]
-            extern "rust-call" fn call(&self, args: ($($args,)*)) -> Result {
-                let ($($args,)*) = args;
-                (*self)($($args,)*)
+    macro_rules! def_fn(
+        ($($args:ident)*) => (
+            impl<Result$(,$args)*>
+            Fn<($($args,)*),Result>
+            for extern "Rust" fn($($args: $args,)*) -> Result {
+                #[allow(non_snake_case)]
+                extern "rust-call" fn call(&self, args: ($($args,)*)) -> Result {
+                    let ($($args,)*) = args;
+                    (*self)($($args,)*)
+                }
             }
-        }
+        )
     )
-)
 
-def_fn!(A0 A1)
-def_fn!(A0 A1 A2)
-def_fn!(A0 A1 A2 A3)
-def_fn!(A0 A1 A2 A3 A4)
-def_fn!(A0 A1 A2 A3 A4 A5)
-def_fn!(A0 A1 A2 A3 A4 A5 A6)
-def_fn!(A0 A1 A2 A3 A4 A5 A6 A7)
-def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8)
-def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9)
-def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10)
-def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11)
-def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12)
-def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13)
-def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14)
-def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15)
+    def_fn!(A0 A1)
+    def_fn!(A0 A1 A2)
+    def_fn!(A0 A1 A2 A3)
+    def_fn!(A0 A1 A2 A3 A4)
+    def_fn!(A0 A1 A2 A3 A4 A5)
+    def_fn!(A0 A1 A2 A3 A4 A5 A6)
+    def_fn!(A0 A1 A2 A3 A4 A5 A6 A7)
+    def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8)
+    def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9)
+    def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10)
+    def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11)
+    def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12)
+    def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13)
+    def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14)
+    def_fn!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15)
+}