diff options
| author | bors <bors@rust-lang.org> | 2019-05-25 04:10:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-05-25 04:10:07 +0000 |
| commit | 315ab95a9c13cbb69ae8538fcd69b9f7b0c30f89 (patch) | |
| tree | 11c1b9e9c76d0de8760e02fdca7690e9b8bfd0de /src/liballoc | |
| parent | 524580312039e4fa5ccf91e8f7093cd755bc1aad (diff) | |
| parent | 19b5a103461c7bce5d53db64380360a684c1ce7d (diff) | |
| download | rust-315ab95a9c13cbb69ae8538fcd69b9f7b0c30f89.tar.gz rust-315ab95a9c13cbb69ae8538fcd69b9f7b0c30f89.zip | |
Auto merge of #61150 - Centril:rollup-wmm7qga, r=Centril
Rollup of 13 pull requests Successful merges: - #61026 (Tweak macro parse errors when reaching EOF during macro call parse) - #61095 (Update cargo) - #61096 (tidy: don't short-circuit on license error) - #61107 (Fix a couple docs typos) - #61110 (Revert edition-guide toolstate override) - #61111 (Fixed type-alias-bounds lint doc) - #61113 (Deprecate `FnBox`. `Box<dyn FnOnce()>` can be called directly, since 1.35) - #61116 (Remove the incorrect warning from README.md) - #61118 (Dont ICE on an attempt to use GAT without feature gate) - #61121 (improve debug-printing of scalars) - #61125 (Updated my mailmap entry) - #61134 (Annotate each `reverse_bits` with `#[must_use]`) - #61138 (Move async/await tests to their own folder) Failed merges: r? @ghost
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 97c2d8e7a8e..bf8f5b8b91a 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -759,13 +759,14 @@ impl<A, F: Fn<A> + ?Sized> Fn<A> for Box<F> { } } +/// `FnBox` is deprecated and will be removed. +/// `Box<dyn FnOnce()>` can be called directly, since Rust 1.35.0. +/// /// `FnBox` is a version of the `FnOnce` intended for use with boxed -/// closure objects. The idea is that where one would normally store a -/// `Box<dyn FnOnce()>` in a data structure, you should use +/// closure objects. The idea was that where one would normally store a +/// `Box<dyn FnOnce()>` in a data structure, you whould use /// `Box<dyn FnBox()>`. The two traits behave essentially the same, except -/// that a `FnBox` closure can only be called if it is boxed. (Note -/// that `FnBox` may be deprecated in the future if `Box<dyn FnOnce()>` -/// closures become directly usable.) +/// that a `FnBox` closure can only be called if it is boxed. /// /// # Examples /// @@ -777,6 +778,7 @@ impl<A, F: Fn<A> + ?Sized> Fn<A> for Box<F> { /// /// ``` /// #![feature(fnbox)] +/// #![allow(deprecated)] /// /// use std::boxed::FnBox; /// use std::collections::HashMap; @@ -796,16 +798,38 @@ impl<A, F: Fn<A> + ?Sized> Fn<A> for Box<F> { /// } /// } /// ``` +/// +/// In Rust 1.35.0 or later, use `FnOnce`, `FnMut`, or `Fn` instead: +/// +/// ``` +/// use std::collections::HashMap; +/// +/// fn make_map() -> HashMap<i32, Box<dyn FnOnce() -> i32>> { +/// let mut map: HashMap<i32, Box<dyn FnOnce() -> i32>> = HashMap::new(); +/// map.insert(1, Box::new(|| 22)); +/// map.insert(2, Box::new(|| 44)); +/// map +/// } +/// +/// fn main() { +/// let mut map = make_map(); +/// for i in &[1, 2] { +/// let f = map.remove(&i).unwrap(); +/// assert_eq!(f(), i * 22); +/// } +/// } +/// ``` #[rustc_paren_sugar] -#[unstable(feature = "fnbox", - reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")] +#[unstable(feature = "fnbox", issue = "28796")] +#[rustc_deprecated(reason = "use `FnOnce`, `FnMut`, or `Fn` instead", since = "1.37.0")] pub trait FnBox<A>: FnOnce<A> { /// Performs the call operation. fn call_box(self: Box<Self>, args: A) -> Self::Output; } -#[unstable(feature = "fnbox", - reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")] +#[unstable(feature = "fnbox", issue = "28796")] +#[rustc_deprecated(reason = "use `FnOnce`, `FnMut`, or `Fn` instead", since = "1.37.0")] +#[allow(deprecated, deprecated_in_future)] impl<A, F> FnBox<A> for F where F: FnOnce<A> { |
