about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorMasaki Hara <ackie.h.gmai@gmail.com>2018-10-28 15:28:15 +0900
committerCrLF0710 <crlf0710@gmail.com>2019-04-05 02:26:51 +0800
commit059ec76d9b2ba33be5d7b092ffeb401590a5d39d (patch)
tree44e5505c8b940d2e37407f220d7fc6ca3e16158d /src/liballoc
parent79941973af54db7f7b941582fdc9537b2ee95a00 (diff)
downloadrust-059ec76d9b2ba33be5d7b092ffeb401590a5d39d.tar.gz
rust-059ec76d9b2ba33be5d7b092ffeb401590a5d39d.zip
Add Fn* blanket impls for Box.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/boxed.rs33
-rw-r--r--src/liballoc/lib.rs1
2 files changed, 34 insertions, 0 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index 9166f917293..09554a1a34d 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -694,6 +694,37 @@ impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {
 #[stable(feature = "fused", since = "1.26.0")]
 impl<I: FusedIterator + ?Sized> FusedIterator for Box<I> {}
 
+#[cfg(not(stage0))]
+#[unstable(feature = "boxed_closure_impls",
+           reason = "Box<FnOnce> relies on unsized rvalues and needs to be tested more",
+           issue = "48055")]
+impl<A, F: FnOnce<A> + ?Sized> FnOnce<A> for Box<F> {
+    type Output = <F as FnOnce<A>>::Output;
+
+    default extern "rust-call" fn call_once(self, args: A) -> Self::Output {
+        <F as FnOnce<A>>::call_once(*self, args)
+    }
+}
+
+#[cfg(not(stage0))]
+#[unstable(feature = "boxed_closure_impls",
+           reason = "Box<FnOnce> relies on unsized rvalues and needs to be tested more",
+           issue = "48055")]
+impl<A, F: FnMut<A> + ?Sized> FnMut<A> for Box<F> {
+    extern "rust-call" fn call_mut(&mut self, args: A) -> Self::Output {
+        <F as FnMut<A>>::call_mut(self, args)
+    }
+}
+
+#[cfg(not(stage0))]
+#[unstable(feature = "boxed_closure_impls",
+           reason = "Box<FnOnce> relies on unsized rvalues and needs to be tested more",
+           issue = "48055")]
+impl<A, F: Fn<A> + ?Sized> Fn<A> for Box<F> {
+    extern "rust-call" fn call(&self, args: A) -> Self::Output {
+        <F as Fn<A>>::call(self, args)
+    }
+}
 
 /// `FnBox` is a version of the `FnOnce` intended for use with boxed
 /// closure objects. The idea is that where one would normally store a
@@ -752,6 +783,7 @@ impl<A, F> FnBox<A> for F
 #[unstable(feature = "fnbox",
            reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
 impl<A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + '_> {
+    #[cfg(stage0)]
     type Output = R;
 
     extern "rust-call" fn call_once(self, args: A) -> R {
@@ -762,6 +794,7 @@ impl<A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + '_> {
 #[unstable(feature = "fnbox",
            reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
 impl<A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + Send + '_> {
+    #[cfg(stage0)]
     type Output = R;
 
     extern "rust-call" fn call_once(self, args: A) -> R {
diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index 90ff56814fb..9064b4ccd6a 100644
--- a/src/liballoc/lib.rs
+++ b/src/liballoc/lib.rs
@@ -107,6 +107,7 @@
 #![feature(unboxed_closures)]
 #![feature(unicode_internals)]
 #![feature(unsize)]
+#![feature(unsized_locals)]
 #![feature(allocator_internals)]
 #![feature(on_unimplemented)]
 #![feature(rustc_const_unstable)]