From 059ec76d9b2ba33be5d7b092ffeb401590a5d39d Mon Sep 17 00:00:00 2001 From: Masaki Hara Date: Sun, 28 Oct 2018 15:28:15 +0900 Subject: [PATCH] Add Fn* blanket impls for Box. --- src/liballoc/boxed.rs | 33 +++++++++++++++++++++++++++++++++ src/liballoc/lib.rs | 1 + 2 files changed, 34 insertions(+) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 9166f917293d1..09554a1a34da8 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -694,6 +694,37 @@ impl ExactSizeIterator for Box { #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Box {} +#[cfg(not(stage0))] +#[unstable(feature = "boxed_closure_impls", + reason = "Box relies on unsized rvalues and needs to be tested more", + issue = "48055")] +impl + ?Sized> FnOnce for Box { + type Output = >::Output; + + default extern "rust-call" fn call_once(self, args: A) -> Self::Output { + >::call_once(*self, args) + } +} + +#[cfg(not(stage0))] +#[unstable(feature = "boxed_closure_impls", + reason = "Box relies on unsized rvalues and needs to be tested more", + issue = "48055")] +impl + ?Sized> FnMut for Box { + extern "rust-call" fn call_mut(&mut self, args: A) -> Self::Output { + >::call_mut(self, args) + } +} + +#[cfg(not(stage0))] +#[unstable(feature = "boxed_closure_impls", + reason = "Box relies on unsized rvalues and needs to be tested more", + issue = "48055")] +impl + ?Sized> Fn for Box { + extern "rust-call" fn call(&self, args: A) -> Self::Output { + >::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 FnBox for F #[unstable(feature = "fnbox", reason = "will be deprecated if and when `Box` becomes usable", issue = "28796")] impl FnOnce for Box + '_> { + #[cfg(stage0)] type Output = R; extern "rust-call" fn call_once(self, args: A) -> R { @@ -762,6 +794,7 @@ impl FnOnce for Box + '_> { #[unstable(feature = "fnbox", reason = "will be deprecated if and when `Box` becomes usable", issue = "28796")] impl FnOnce for Box + 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 90ff56814fbb1..9064b4ccd6a88 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)]