Skip to content

Commit 059ec76

Browse files
qnighycrlf0710
authored andcommitted
Add Fn* blanket impls for Box.
1 parent 7994197 commit 059ec76

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/liballoc/boxed.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,37 @@ impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {
694694
#[stable(feature = "fused", since = "1.26.0")]
695695
impl<I: FusedIterator + ?Sized> FusedIterator for Box<I> {}
696696

697+
#[cfg(not(stage0))]
698+
#[unstable(feature = "boxed_closure_impls",
699+
reason = "Box<FnOnce> relies on unsized rvalues and needs to be tested more",
700+
issue = "48055")]
701+
impl<A, F: FnOnce<A> + ?Sized> FnOnce<A> for Box<F> {
702+
type Output = <F as FnOnce<A>>::Output;
703+
704+
default extern "rust-call" fn call_once(self, args: A) -> Self::Output {
705+
<F as FnOnce<A>>::call_once(*self, args)
706+
}
707+
}
708+
709+
#[cfg(not(stage0))]
710+
#[unstable(feature = "boxed_closure_impls",
711+
reason = "Box<FnOnce> relies on unsized rvalues and needs to be tested more",
712+
issue = "48055")]
713+
impl<A, F: FnMut<A> + ?Sized> FnMut<A> for Box<F> {
714+
extern "rust-call" fn call_mut(&mut self, args: A) -> Self::Output {
715+
<F as FnMut<A>>::call_mut(self, args)
716+
}
717+
}
718+
719+
#[cfg(not(stage0))]
720+
#[unstable(feature = "boxed_closure_impls",
721+
reason = "Box<FnOnce> relies on unsized rvalues and needs to be tested more",
722+
issue = "48055")]
723+
impl<A, F: Fn<A> + ?Sized> Fn<A> for Box<F> {
724+
extern "rust-call" fn call(&self, args: A) -> Self::Output {
725+
<F as Fn<A>>::call(self, args)
726+
}
727+
}
697728

698729
/// `FnBox` is a version of the `FnOnce` intended for use with boxed
699730
/// closure objects. The idea is that where one would normally store a
@@ -752,6 +783,7 @@ impl<A, F> FnBox<A> for F
752783
#[unstable(feature = "fnbox",
753784
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
754785
impl<A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + '_> {
786+
#[cfg(stage0)]
755787
type Output = R;
756788

757789
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> + '_> {
762794
#[unstable(feature = "fnbox",
763795
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
764796
impl<A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + Send + '_> {
797+
#[cfg(stage0)]
765798
type Output = R;
766799

767800
extern "rust-call" fn call_once(self, args: A) -> R {

src/liballoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
#![feature(unboxed_closures)]
108108
#![feature(unicode_internals)]
109109
#![feature(unsize)]
110+
#![feature(unsized_locals)]
110111
#![feature(allocator_internals)]
111112
#![feature(on_unimplemented)]
112113
#![feature(rustc_const_unstable)]

0 commit comments

Comments
 (0)