diff options
| author | bors <bors@rust-lang.org> | 2019-04-05 17:45:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-04-05 17:45:43 +0000 |
| commit | acd8dd6a50d505057a7d7ad8d0d7a4c2bd274200 (patch) | |
| tree | db3cdcdf3bc1a839ef3ce43ca6eddef9225c1094 /src/liballoc | |
| parent | 20dbf28624db446c0cf67be4cc71a85931947907 (diff) | |
| parent | 812d89c87d9346ac4b70426b67a8eb989a13c853 (diff) | |
| download | rust-acd8dd6a50d505057a7d7ad8d0d7a4c2bd274200.tar.gz rust-acd8dd6a50d505057a7d7ad8d0d7a4c2bd274200.zip | |
Auto merge of #59500 - crlf0710:boxed-closure-impls, r=cramertj
Unsized rvalues: implement boxed closure impls. (2nd try) This is a rebase of S-blocked-closed PR #55431 to current master. LLVM has moved forward since then, so maybe we can check whether the new LLVM 8.0 version unblocked this work.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 48 | ||||
| -rw-r--r-- | src/liballoc/lib.rs | 1 |
2 files changed, 24 insertions, 25 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index b2315c6a739..f6dee7c9eef 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -694,6 +694,28 @@ impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> { #[stable(feature = "fused", since = "1.26.0")] impl<I: FusedIterator + ?Sized> FusedIterator for Box<I> {} +#[stable(feature = "boxed_closure_impls", since = "1.35.0")] +impl<A, F: FnOnce<A> + ?Sized> FnOnce<A> for Box<F> { + type Output = <F as FnOnce<A>>::Output; + + extern "rust-call" fn call_once(self, args: A) -> Self::Output { + <F as FnOnce<A>>::call_once(*self, args) + } +} + +#[stable(feature = "boxed_closure_impls", since = "1.35.0")] +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) + } +} + +#[stable(feature = "boxed_closure_impls", since = "1.35.0")] +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 @@ -735,9 +757,7 @@ impl<I: FusedIterator + ?Sized> FusedIterator for Box<I> {} #[rustc_paren_sugar] #[unstable(feature = "fnbox", reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")] -pub trait FnBox<A> { - type Output; - +pub trait FnBox<A>: FnOnce<A> { fn call_box(self: Box<Self>, args: A) -> Self::Output; } @@ -746,33 +766,11 @@ pub trait FnBox<A> { impl<A, F> FnBox<A> for F where F: FnOnce<A> { - type Output = F::Output; - fn call_box(self: Box<F>, args: A) -> F::Output { self.call_once(args) } } -#[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> + '_> { - type Output = R; - - extern "rust-call" fn call_once(self, args: A) -> R { - self.call_box(args) - } -} - -#[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 + '_> { - type Output = R; - - extern "rust-call" fn call_once(self, args: A) -> R { - self.call_box(args) - } -} - #[unstable(feature = "coerce_unsized", issue = "27732")] impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {} 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)] |
