diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 97c2d8e7a8e79..bf8f5b8b91a1e 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -759,13 +759,14 @@ impl + ?Sized> Fn for Box { } } +/// `FnBox` is deprecated and will be removed. +/// `Box` 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` in a data structure, you should use +/// closure objects. The idea was that where one would normally store a +/// `Box` in a data structure, you whould use /// `Box`. 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` -/// closures become directly usable.) +/// that a `FnBox` closure can only be called if it is boxed. /// /// # Examples /// @@ -777,6 +778,7 @@ impl + ?Sized> Fn for Box { /// /// ``` /// #![feature(fnbox)] +/// #![allow(deprecated)] /// /// use std::boxed::FnBox; /// use std::collections::HashMap; @@ -796,16 +798,38 @@ impl + ?Sized> Fn for Box { /// } /// } /// ``` +/// +/// In Rust 1.35.0 or later, use `FnOnce`, `FnMut`, or `Fn` instead: +/// +/// ``` +/// use std::collections::HashMap; +/// +/// fn make_map() -> HashMap i32>> { +/// let mut map: HashMap 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` 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: FnOnce { /// Performs the call operation. fn call_box(self: Box, args: A) -> Self::Output; } -#[unstable(feature = "fnbox", - reason = "will be deprecated if and when `Box` 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 FnBox for F where F: FnOnce { diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 7f7db2a21251a..8bd0d74cd1710 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -22,7 +22,6 @@ #![unstable(feature = "test", issue = "27812")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/", test(attr(deny(warnings))))] #![feature(asm)] -#![feature(fnbox)] #![cfg_attr(any(unix, target_os = "cloudabi"), feature(libc, rustc_private))] #![feature(nll)] #![feature(set_stdio)] @@ -56,7 +55,6 @@ pub use self::TestResult::*; use std::any::Any; use std::borrow::Cow; -use std::boxed::FnBox; use std::cmp; use std::collections::BTreeMap; use std::env; @@ -174,7 +172,7 @@ pub trait TDynBenchFn: Send { pub enum TestFn { StaticTestFn(fn()), StaticBenchFn(fn(&mut Bencher)), - DynTestFn(Box), + DynTestFn(Box), DynBenchFn(Box), } @@ -1447,7 +1445,7 @@ pub fn run_test( desc: TestDesc, monitor_ch: Sender, nocapture: bool, - testfn: Box, + testfn: Box, concurrency: Concurrent, ) { // Buffer for capturing standard I/O diff --git a/src/test/run-pass/unsized-locals/fnbox-compat.rs b/src/test/run-pass/unsized-locals/fnbox-compat.rs index 5ec54ada13bb0..74a4dd5d8515b 100644 --- a/src/test/run-pass/unsized-locals/fnbox-compat.rs +++ b/src/test/run-pass/unsized-locals/fnbox-compat.rs @@ -1,4 +1,5 @@ #![feature(fnbox)] +#![allow(deprecated, deprecated_in_future)] use std::boxed::FnBox; diff --git a/src/test/ui/confuse-field-and-method/issue-2392.rs b/src/test/ui/confuse-field-and-method/issue-2392.rs index 41287c2591497..c242b6c2c20a2 100644 --- a/src/test/ui/confuse-field-and-method/issue-2392.rs +++ b/src/test/ui/confuse-field-and-method/issue-2392.rs @@ -1,7 +1,3 @@ -#![feature(core, fnbox)] - -use std::boxed::FnBox; - struct FuncContainer { f1: fn(data: u8), f2: extern "C" fn(data: u8), @@ -18,7 +14,7 @@ struct Obj where F: FnOnce() -> u32 { } struct BoxedObj { - boxed_closure: Box u32>, + boxed_closure: Box u32>, } struct Wrapper where F: FnMut() -> u32 { @@ -29,8 +25,8 @@ fn func() -> u32 { 0 } -fn check_expression() -> Obj u32>> { - Obj { closure: Box::new(|| 42_u32) as Box u32>, not_closure: 42 } +fn check_expression() -> Obj u32>> { + Obj { closure: Box::new(|| 42_u32) as Box u32>, not_closure: 42 } } fn main() { @@ -48,7 +44,7 @@ fn main() { let boxed_fn = BoxedObj { boxed_closure: Box::new(func) }; boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found - let boxed_closure = BoxedObj { boxed_closure: Box::new(|| 42_u32) as Box u32> }; + let boxed_closure = BoxedObj { boxed_closure: Box::new(|| 42_u32) as Box u32> }; boxed_closure.boxed_closure();//~ ERROR no method named `boxed_closure` found // test expression writing in the notes diff --git a/src/test/ui/confuse-field-and-method/issue-2392.stderr b/src/test/ui/confuse-field-and-method/issue-2392.stderr index 2107318d87b5b..351cfef1b53ea 100644 --- a/src/test/ui/confuse-field-and-method/issue-2392.stderr +++ b/src/test/ui/confuse-field-and-method/issue-2392.stderr @@ -1,5 +1,5 @@ -error[E0599]: no method named `closure` found for type `Obj<[closure@$DIR/issue-2392.rs:39:36: 39:41]>` in the current scope - --> $DIR/issue-2392.rs:40:15 +error[E0599]: no method named `closure` found for type `Obj<[closure@$DIR/issue-2392.rs:35:36: 35:41]>` in the current scope + --> $DIR/issue-2392.rs:36:15 | LL | struct Obj where F: FnOnce() -> u32 { | -------------------------------------- method `closure` not found for this @@ -11,8 +11,8 @@ help: to call the function stored in `closure`, surround the field access with p LL | (o_closure.closure)(); | ^ ^ -error[E0599]: no method named `not_closure` found for type `Obj<[closure@$DIR/issue-2392.rs:39:36: 39:41]>` in the current scope - --> $DIR/issue-2392.rs:42:15 +error[E0599]: no method named `not_closure` found for type `Obj<[closure@$DIR/issue-2392.rs:35:36: 35:41]>` in the current scope + --> $DIR/issue-2392.rs:38:15 | LL | struct Obj where F: FnOnce() -> u32 { | -------------------------------------- method `not_closure` not found for this @@ -23,7 +23,7 @@ LL | o_closure.not_closure(); | field, not a method error[E0599]: no method named `closure` found for type `Obj u32 {func}>` in the current scope - --> $DIR/issue-2392.rs:46:12 + --> $DIR/issue-2392.rs:42:12 | LL | struct Obj where F: FnOnce() -> u32 { | -------------------------------------- method `closure` not found for this @@ -36,7 +36,7 @@ LL | (o_func.closure)(); | ^ ^ error[E0599]: no method named `boxed_closure` found for type `BoxedObj` in the current scope - --> $DIR/issue-2392.rs:49:14 + --> $DIR/issue-2392.rs:45:14 | LL | struct BoxedObj { | --------------- method `boxed_closure` not found for this @@ -49,7 +49,7 @@ LL | (boxed_fn.boxed_closure)(); | ^ ^ error[E0599]: no method named `boxed_closure` found for type `BoxedObj` in the current scope - --> $DIR/issue-2392.rs:52:19 + --> $DIR/issue-2392.rs:48:19 | LL | struct BoxedObj { | --------------- method `boxed_closure` not found for this @@ -62,7 +62,7 @@ LL | (boxed_closure.boxed_closure)(); | ^ ^ error[E0599]: no method named `closure` found for type `Obj u32 {func}>` in the current scope - --> $DIR/issue-2392.rs:57:12 + --> $DIR/issue-2392.rs:53:12 | LL | struct Obj where F: FnOnce() -> u32 { | -------------------------------------- method `closure` not found for this @@ -75,7 +75,7 @@ LL | (w.wrap.closure)(); | ^ ^ error[E0599]: no method named `not_closure` found for type `Obj u32 {func}>` in the current scope - --> $DIR/issue-2392.rs:59:12 + --> $DIR/issue-2392.rs:55:12 | LL | struct Obj where F: FnOnce() -> u32 { | -------------------------------------- method `not_closure` not found for this @@ -85,8 +85,8 @@ LL | w.wrap.not_closure(); | | | field, not a method -error[E0599]: no method named `closure` found for type `Obj + 'static)>>` in the current scope - --> $DIR/issue-2392.rs:62:24 +error[E0599]: no method named `closure` found for type `Obj u32 + 'static)>>` in the current scope + --> $DIR/issue-2392.rs:58:24 | LL | struct Obj where F: FnOnce() -> u32 { | -------------------------------------- method `closure` not found for this @@ -99,7 +99,7 @@ LL | (check_expression().closure)(); | ^ ^ error[E0599]: no method named `f1` found for type `FuncContainer` in the current scope - --> $DIR/issue-2392.rs:68:31 + --> $DIR/issue-2392.rs:64:31 | LL | struct FuncContainer { | -------------------- method `f1` not found for this @@ -112,7 +112,7 @@ LL | ((*self.container).f1)(1); | ^ ^ error[E0599]: no method named `f2` found for type `FuncContainer` in the current scope - --> $DIR/issue-2392.rs:69:31 + --> $DIR/issue-2392.rs:65:31 | LL | struct FuncContainer { | -------------------- method `f2` not found for this @@ -125,7 +125,7 @@ LL | ((*self.container).f2)(1); | ^ ^ error[E0599]: no method named `f3` found for type `FuncContainer` in the current scope - --> $DIR/issue-2392.rs:70:31 + --> $DIR/issue-2392.rs:66:31 | LL | struct FuncContainer { | -------------------- method `f3` not found for this