From 4f04f975aee2fcbc3fc17ef7693920497a323e1c Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 10 Dec 2017 12:58:22 -0500 Subject: [PATCH] Replace libtest/lib.rs:FnBox with std::boxed::FnBox. Fixes https://github.com/rust-lang/rust/issues/41810. --- src/librustdoc/test.rs | 2 +- src/libtest/lib.rs | 50 +++++++++++++------------------ src/tools/compiletest/src/main.rs | 2 +- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 74a16cb867d74..d4fb4d73dd3d3 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -534,7 +534,7 @@ impl Collector { should_panic: testing::ShouldPanic::No, allow_fail, }, - testfn: testing::DynTestFn(box move |()| { + testfn: testing::DynTestFn(box move || { let panic = io::set_panic(None); let print = io::set_print(None); match { diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index bc96a5d6740c4..0d837c470a223 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -35,6 +35,7 @@ #![deny(warnings)] #![feature(asm)] +#![feature(fnbox)] #![cfg_attr(unix, feature(libc))] #![feature(set_stdio)] #![feature(panic_unwind)] @@ -56,6 +57,7 @@ use self::OutputLocation::*; use std::panic::{catch_unwind, AssertUnwindSafe}; use std::any::Any; +use std::boxed::FnBox; use std::cmp; use std::collections::BTreeMap; use std::env; @@ -133,16 +135,6 @@ pub trait TDynBenchFn: Send { fn run(&self, harness: &mut Bencher); } -pub trait FnBox: Send + 'static { - fn call_box(self: Box, t: T); -} - -impl FnBox for F { - fn call_box(self: Box, t: T) { - (*self)(t) - } -} - // A function that runs a test. If the function returns successfully, // the test succeeds; if the function panics then the test fails. We // may need to come up with a more clever definition of test in order @@ -150,7 +142,7 @@ impl FnBox for F { pub enum TestFn { StaticTestFn(fn()), StaticBenchFn(fn(&mut Bencher)), - DynTestFn(Box>), + DynTestFn(Box), DynBenchFn(Box), } @@ -1337,14 +1329,14 @@ pub fn convert_benchmarks_to_tests(tests: Vec) -> Vec { - DynTestFn(Box::new(move |()| { + DynTestFn(Box::new(move || { bench::run_once(|b| { __rust_begin_short_backtrace(|| bench.run(b)) }) })) } StaticBenchFn(benchfn) => { - DynTestFn(Box::new(move |()| { + DynTestFn(Box::new(move || { bench::run_once(|b| { __rust_begin_short_backtrace(|| benchfn(b)) }) @@ -1379,7 +1371,7 @@ pub fn run_test(opts: &TestOpts, fn run_test_inner(desc: TestDesc, monitor_ch: Sender, nocapture: bool, - testfn: Box>) { + testfn: Box) { struct Sink(Arc>>); impl Write for Sink { fn write(&mut self, data: &[u8]) -> io::Result { @@ -1405,9 +1397,7 @@ pub fn run_test(opts: &TestOpts, None }; - let result = catch_unwind(AssertUnwindSafe(|| { - testfn.call_box(()) - })); + let result = catch_unwind(AssertUnwindSafe(testfn)); if let Some((printio, panicio)) = oldio { io::set_print(printio); @@ -1449,14 +1439,14 @@ pub fn run_test(opts: &TestOpts, return; } DynTestFn(f) => { - let cb = move |()| { - __rust_begin_short_backtrace(|| f.call_box(())) + let cb = move || { + __rust_begin_short_backtrace(f) }; run_test_inner(desc, monitor_ch, opts.nocapture, Box::new(cb)) } StaticTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture, - Box::new(move |()| __rust_begin_short_backtrace(f))), + Box::new(move || __rust_begin_short_backtrace(f))), } } @@ -1720,7 +1710,7 @@ mod tests { should_panic: ShouldPanic::No, allow_fail: false, }, - testfn: DynTestFn(Box::new(move |()| f())), + testfn: DynTestFn(Box::new(f)), }; let (tx, rx) = channel(); run_test(&TestOpts::new(), false, desc, tx); @@ -1738,7 +1728,7 @@ mod tests { should_panic: ShouldPanic::No, allow_fail: false, }, - testfn: DynTestFn(Box::new(move |()| f())), + testfn: DynTestFn(Box::new(f)), }; let (tx, rx) = channel(); run_test(&TestOpts::new(), false, desc, tx); @@ -1758,7 +1748,7 @@ mod tests { should_panic: ShouldPanic::Yes, allow_fail: false, }, - testfn: DynTestFn(Box::new(move |()| f())), + testfn: DynTestFn(Box::new(f)), }; let (tx, rx) = channel(); run_test(&TestOpts::new(), false, desc, tx); @@ -1778,7 +1768,7 @@ mod tests { should_panic: ShouldPanic::YesWithMessage("error message"), allow_fail: false, }, - testfn: DynTestFn(Box::new(move |()| f())), + testfn: DynTestFn(Box::new(f)), }; let (tx, rx) = channel(); run_test(&TestOpts::new(), false, desc, tx); @@ -1800,7 +1790,7 @@ mod tests { should_panic: ShouldPanic::YesWithMessage(expected), allow_fail: false, }, - testfn: DynTestFn(Box::new(move |()| f())), + testfn: DynTestFn(Box::new(f)), }; let (tx, rx) = channel(); run_test(&TestOpts::new(), false, desc, tx); @@ -1818,7 +1808,7 @@ mod tests { should_panic: ShouldPanic::Yes, allow_fail: false, }, - testfn: DynTestFn(Box::new(move |()| f())), + testfn: DynTestFn(Box::new(f)), }; let (tx, rx) = channel(); run_test(&TestOpts::new(), false, desc, tx); @@ -1852,7 +1842,7 @@ mod tests { should_panic: ShouldPanic::No, allow_fail: false, }, - testfn: DynTestFn(Box::new(move |()| {})), + testfn: DynTestFn(Box::new(move || {})), }, TestDescAndFn { desc: TestDesc { @@ -1861,7 +1851,7 @@ mod tests { should_panic: ShouldPanic::No, allow_fail: false, }, - testfn: DynTestFn(Box::new(move |()| {})), + testfn: DynTestFn(Box::new(move || {})), }]; let filtered = filter_tests(&opts, tests); @@ -1885,7 +1875,7 @@ mod tests { should_panic: ShouldPanic::No, allow_fail: false, }, - testfn: DynTestFn(Box::new(move |()| {})) + testfn: DynTestFn(Box::new(move || {})) }) .collect() } @@ -1967,7 +1957,7 @@ mod tests { should_panic: ShouldPanic::No, allow_fail: false, }, - testfn: DynTestFn(Box::new(move |()| testfn())), + testfn: DynTestFn(Box::new(testfn)), }; tests.push(test); } diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index fac3b71f82cc4..8ad27693629a0 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -710,7 +710,7 @@ pub fn make_test_name(config: &Config, testpaths: &TestPaths) -> test::TestName pub fn make_test_closure(config: &Config, testpaths: &TestPaths) -> test::TestFn { let config = config.clone(); let testpaths = testpaths.clone(); - test::DynTestFn(Box::new(move |()| runtest::run(config, &testpaths))) + test::DynTestFn(Box::new(move || runtest::run(config, &testpaths))) } /// Returns (Path to GDB, GDB Version, GDB has Rust Support)