Skip to content

Commit

Permalink
Add Fn* blanket impls for Box.
Browse files Browse the repository at this point in the history
  • Loading branch information
qnighy authored and crlf0710 committed Apr 4, 2019
1 parent 7994197 commit 059ec76
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/liballoc/boxed.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Expand Up @@ -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)]
Expand Down

0 comments on commit 059ec76

Please sign in to comment.