Skip to content

Commit 4f04f97

Browse files
committed
Replace libtest/lib.rs:FnBox with std::boxed::FnBox.
Fixes rust-lang#41810.
1 parent 2537a49 commit 4f04f97

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

src/librustdoc/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ impl Collector {
534534
should_panic: testing::ShouldPanic::No,
535535
allow_fail,
536536
},
537-
testfn: testing::DynTestFn(box move |()| {
537+
testfn: testing::DynTestFn(box move || {
538538
let panic = io::set_panic(None);
539539
let print = io::set_print(None);
540540
match {

src/libtest/lib.rs

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#![deny(warnings)]
3636

3737
#![feature(asm)]
38+
#![feature(fnbox)]
3839
#![cfg_attr(unix, feature(libc))]
3940
#![feature(set_stdio)]
4041
#![feature(panic_unwind)]
@@ -56,6 +57,7 @@ use self::OutputLocation::*;
5657

5758
use std::panic::{catch_unwind, AssertUnwindSafe};
5859
use std::any::Any;
60+
use std::boxed::FnBox;
5961
use std::cmp;
6062
use std::collections::BTreeMap;
6163
use std::env;
@@ -133,24 +135,14 @@ pub trait TDynBenchFn: Send {
133135
fn run(&self, harness: &mut Bencher);
134136
}
135137

136-
pub trait FnBox<T>: Send + 'static {
137-
fn call_box(self: Box<Self>, t: T);
138-
}
139-
140-
impl<T, F: FnOnce(T) + Send + 'static> FnBox<T> for F {
141-
fn call_box(self: Box<F>, t: T) {
142-
(*self)(t)
143-
}
144-
}
145-
146138
// A function that runs a test. If the function returns successfully,
147139
// the test succeeds; if the function panics then the test fails. We
148140
// may need to come up with a more clever definition of test in order
149141
// to support isolation of tests into threads.
150142
pub enum TestFn {
151143
StaticTestFn(fn()),
152144
StaticBenchFn(fn(&mut Bencher)),
153-
DynTestFn(Box<FnBox<()>>),
145+
DynTestFn(Box<FnBox() + Send>),
154146
DynBenchFn(Box<TDynBenchFn + 'static>),
155147
}
156148

@@ -1337,14 +1329,14 @@ pub fn convert_benchmarks_to_tests(tests: Vec<TestDescAndFn>) -> Vec<TestDescAnd
13371329
tests.into_iter().map(|x| {
13381330
let testfn = match x.testfn {
13391331
DynBenchFn(bench) => {
1340-
DynTestFn(Box::new(move |()| {
1332+
DynTestFn(Box::new(move || {
13411333
bench::run_once(|b| {
13421334
__rust_begin_short_backtrace(|| bench.run(b))
13431335
})
13441336
}))
13451337
}
13461338
StaticBenchFn(benchfn) => {
1347-
DynTestFn(Box::new(move |()| {
1339+
DynTestFn(Box::new(move || {
13481340
bench::run_once(|b| {
13491341
__rust_begin_short_backtrace(|| benchfn(b))
13501342
})
@@ -1379,7 +1371,7 @@ pub fn run_test(opts: &TestOpts,
13791371
fn run_test_inner(desc: TestDesc,
13801372
monitor_ch: Sender<MonitorMsg>,
13811373
nocapture: bool,
1382-
testfn: Box<FnBox<()>>) {
1374+
testfn: Box<FnBox() + Send>) {
13831375
struct Sink(Arc<Mutex<Vec<u8>>>);
13841376
impl Write for Sink {
13851377
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
@@ -1405,9 +1397,7 @@ pub fn run_test(opts: &TestOpts,
14051397
None
14061398
};
14071399

1408-
let result = catch_unwind(AssertUnwindSafe(|| {
1409-
testfn.call_box(())
1410-
}));
1400+
let result = catch_unwind(AssertUnwindSafe(testfn));
14111401

14121402
if let Some((printio, panicio)) = oldio {
14131403
io::set_print(printio);
@@ -1449,14 +1439,14 @@ pub fn run_test(opts: &TestOpts,
14491439
return;
14501440
}
14511441
DynTestFn(f) => {
1452-
let cb = move |()| {
1453-
__rust_begin_short_backtrace(|| f.call_box(()))
1442+
let cb = move || {
1443+
__rust_begin_short_backtrace(f)
14541444
};
14551445
run_test_inner(desc, monitor_ch, opts.nocapture, Box::new(cb))
14561446
}
14571447
StaticTestFn(f) =>
14581448
run_test_inner(desc, monitor_ch, opts.nocapture,
1459-
Box::new(move |()| __rust_begin_short_backtrace(f))),
1449+
Box::new(move || __rust_begin_short_backtrace(f))),
14601450
}
14611451
}
14621452

@@ -1720,7 +1710,7 @@ mod tests {
17201710
should_panic: ShouldPanic::No,
17211711
allow_fail: false,
17221712
},
1723-
testfn: DynTestFn(Box::new(move |()| f())),
1713+
testfn: DynTestFn(Box::new(f)),
17241714
};
17251715
let (tx, rx) = channel();
17261716
run_test(&TestOpts::new(), false, desc, tx);
@@ -1738,7 +1728,7 @@ mod tests {
17381728
should_panic: ShouldPanic::No,
17391729
allow_fail: false,
17401730
},
1741-
testfn: DynTestFn(Box::new(move |()| f())),
1731+
testfn: DynTestFn(Box::new(f)),
17421732
};
17431733
let (tx, rx) = channel();
17441734
run_test(&TestOpts::new(), false, desc, tx);
@@ -1758,7 +1748,7 @@ mod tests {
17581748
should_panic: ShouldPanic::Yes,
17591749
allow_fail: false,
17601750
},
1761-
testfn: DynTestFn(Box::new(move |()| f())),
1751+
testfn: DynTestFn(Box::new(f)),
17621752
};
17631753
let (tx, rx) = channel();
17641754
run_test(&TestOpts::new(), false, desc, tx);
@@ -1778,7 +1768,7 @@ mod tests {
17781768
should_panic: ShouldPanic::YesWithMessage("error message"),
17791769
allow_fail: false,
17801770
},
1781-
testfn: DynTestFn(Box::new(move |()| f())),
1771+
testfn: DynTestFn(Box::new(f)),
17821772
};
17831773
let (tx, rx) = channel();
17841774
run_test(&TestOpts::new(), false, desc, tx);
@@ -1800,7 +1790,7 @@ mod tests {
18001790
should_panic: ShouldPanic::YesWithMessage(expected),
18011791
allow_fail: false,
18021792
},
1803-
testfn: DynTestFn(Box::new(move |()| f())),
1793+
testfn: DynTestFn(Box::new(f)),
18041794
};
18051795
let (tx, rx) = channel();
18061796
run_test(&TestOpts::new(), false, desc, tx);
@@ -1818,7 +1808,7 @@ mod tests {
18181808
should_panic: ShouldPanic::Yes,
18191809
allow_fail: false,
18201810
},
1821-
testfn: DynTestFn(Box::new(move |()| f())),
1811+
testfn: DynTestFn(Box::new(f)),
18221812
};
18231813
let (tx, rx) = channel();
18241814
run_test(&TestOpts::new(), false, desc, tx);
@@ -1852,7 +1842,7 @@ mod tests {
18521842
should_panic: ShouldPanic::No,
18531843
allow_fail: false,
18541844
},
1855-
testfn: DynTestFn(Box::new(move |()| {})),
1845+
testfn: DynTestFn(Box::new(move || {})),
18561846
},
18571847
TestDescAndFn {
18581848
desc: TestDesc {
@@ -1861,7 +1851,7 @@ mod tests {
18611851
should_panic: ShouldPanic::No,
18621852
allow_fail: false,
18631853
},
1864-
testfn: DynTestFn(Box::new(move |()| {})),
1854+
testfn: DynTestFn(Box::new(move || {})),
18651855
}];
18661856
let filtered = filter_tests(&opts, tests);
18671857

@@ -1885,7 +1875,7 @@ mod tests {
18851875
should_panic: ShouldPanic::No,
18861876
allow_fail: false,
18871877
},
1888-
testfn: DynTestFn(Box::new(move |()| {}))
1878+
testfn: DynTestFn(Box::new(move || {}))
18891879
})
18901880
.collect()
18911881
}
@@ -1967,7 +1957,7 @@ mod tests {
19671957
should_panic: ShouldPanic::No,
19681958
allow_fail: false,
19691959
},
1970-
testfn: DynTestFn(Box::new(move |()| testfn())),
1960+
testfn: DynTestFn(Box::new(testfn)),
19711961
};
19721962
tests.push(test);
19731963
}

src/tools/compiletest/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ pub fn make_test_name(config: &Config, testpaths: &TestPaths) -> test::TestName
710710
pub fn make_test_closure(config: &Config, testpaths: &TestPaths) -> test::TestFn {
711711
let config = config.clone();
712712
let testpaths = testpaths.clone();
713-
test::DynTestFn(Box::new(move |()| runtest::run(config, &testpaths)))
713+
test::DynTestFn(Box::new(move || runtest::run(config, &testpaths)))
714714
}
715715

716716
/// Returns (Path to GDB, GDB Version, GDB has Rust Support)

0 commit comments

Comments
 (0)