From ecc3e89dd072ed20d9aa6d53be0ab1c44d160232 Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Mon, 11 Feb 2019 11:09:26 +0900 Subject: [PATCH] Stabilize boxed_closure_impls in 1.35.0. --- .../library-features/boxed-closure-impls.md | 98 ------------------- src/liballoc/boxed.rs | 12 +-- .../run-pass/unsized-locals/box-fnonce.rs | 2 - 3 files changed, 3 insertions(+), 109 deletions(-) delete mode 100644 src/doc/unstable-book/src/library-features/boxed-closure-impls.md diff --git a/src/doc/unstable-book/src/library-features/boxed-closure-impls.md b/src/doc/unstable-book/src/library-features/boxed-closure-impls.md deleted file mode 100644 index 5ceb54ff3b9..00000000000 --- a/src/doc/unstable-book/src/library-features/boxed-closure-impls.md +++ /dev/null @@ -1,98 +0,0 @@ -# `boxed_closure_impls` - -The tracking issue for this feature is [#48055] - -[#48055]: https://github.com/rust-lang/rust/issues/48055 - ------------------------- - -This includes the following blanket impls for closure traits: - -```rust,ignore -impl + ?Sized> FnOnce for Box { - // ... -} -impl + ?Sized> FnMut for Box { - // ... -} -impl + ?Sized> Fn for Box { - // ... -} -``` - -## Usage - -`Box` can be used almost transparently. You can even use `Box` now. - -```rust -#![feature(boxed_closure_impls)] - -fn main() { - let resource = "hello".to_owned(); - // Create a boxed once-callable closure - let f: Box = Box::new(|x| { - let s = resource; - println!("{}", x); - println!("{}", s); - }); - - // Call it - f(&42); -} -``` - -## The reason for instability - -This is unstable because of the first impl. - -It would have been easy if we're allowed to tighten the bound: - -```rust,ignore -impl + ?Sized> FnOnce for Box { - // ... -} -``` - -However, `Box` drops out of the modified impl. -To rescue this, we had had a temporary solution called [`fnbox`][fnbox]. - -[fnbox]: library-features/fnbox.html - -Unfortunately, due to minor coherence reasons, `fnbox` and -`FnOnce for Box` had not been able to coexist. -We had preferred `fnbox` for the time being. - -Now, as [`unsized_locals`][unsized_locals] is implemented, we can just write the -original impl: - -[unsized_locals]: language-features/unsized-locals.html - -```rust,ignore -impl + ?Sized> FnOnce for Box { - type Output = >::Output; - - extern "rust-call" fn call_once(self, args: A) -> Self::Output { - // *self is an unsized rvalue - >::call_once(*self, args) - } -} -``` - -However, since `unsized_locals` is a very young feature, we're careful about -this `FnOnce` impl now. - -There's another reason for instability: for compatibility with `fnbox`, -we currently allow specialization of the `Box` impl: - -```rust,ignore -impl + ?Sized> FnOnce for Box { - type Output = >::Output; - - // we have "default" here - default extern "rust-call" fn call_once(self, args: A) -> Self::Output { - >::call_once(*self, args) - } -} -``` - -This isn't what we desire in the long term. diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index d4fe8be36d6..f6dee7c9eef 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -694,9 +694,7 @@ impl ExactSizeIterator for Box { #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Box {} -#[unstable(feature = "boxed_closure_impls", - reason = "Box relies on unsized rvalues and needs to be tested more", - issue = "48055")] +#[stable(feature = "boxed_closure_impls", since = "1.35.0")] impl + ?Sized> FnOnce for Box { type Output = >::Output; @@ -705,18 +703,14 @@ impl + ?Sized> FnOnce for Box { } } -#[unstable(feature = "boxed_closure_impls", - reason = "Box relies on unsized rvalues and needs to be tested more", - issue = "48055")] +#[stable(feature = "boxed_closure_impls", since = "1.35.0")] impl + ?Sized> FnMut for Box { extern "rust-call" fn call_mut(&mut self, args: A) -> Self::Output { >::call_mut(self, args) } } -#[unstable(feature = "boxed_closure_impls", - reason = "Box relies on unsized rvalues and needs to be tested more", - issue = "48055")] +#[stable(feature = "boxed_closure_impls", since = "1.35.0")] impl + ?Sized> Fn for Box { extern "rust-call" fn call(&self, args: A) -> Self::Output { >::call(self, args) diff --git a/src/test/run-pass/unsized-locals/box-fnonce.rs b/src/test/run-pass/unsized-locals/box-fnonce.rs index 97007a94239..16bdeae4fad 100644 --- a/src/test/run-pass/unsized-locals/box-fnonce.rs +++ b/src/test/run-pass/unsized-locals/box-fnonce.rs @@ -1,5 +1,3 @@ -#![feature(boxed_closure_impls)] - fn call_it(f: Box T>) -> T { f() }