35
35
#![ deny( warnings) ]
36
36
37
37
#![ feature( asm) ]
38
+ #![ feature( fnbox) ]
38
39
#![ cfg_attr( unix, feature( libc) ) ]
39
40
#![ feature( set_stdio) ]
40
41
#![ feature( panic_unwind) ]
@@ -56,6 +57,7 @@ use self::OutputLocation::*;
56
57
57
58
use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
58
59
use std:: any:: Any ;
60
+ use std:: boxed:: FnBox ;
59
61
use std:: cmp;
60
62
use std:: collections:: BTreeMap ;
61
63
use std:: env;
@@ -133,24 +135,14 @@ pub trait TDynBenchFn: Send {
133
135
fn run ( & self , harness : & mut Bencher ) ;
134
136
}
135
137
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
-
146
138
// A function that runs a test. If the function returns successfully,
147
139
// the test succeeds; if the function panics then the test fails. We
148
140
// may need to come up with a more clever definition of test in order
149
141
// to support isolation of tests into threads.
150
142
pub enum TestFn {
151
143
StaticTestFn ( fn ( ) ) ,
152
144
StaticBenchFn ( fn ( & mut Bencher ) ) ,
153
- DynTestFn ( Box < FnBox < ( ) > > ) ,
145
+ DynTestFn ( Box < FnBox ( ) + Send > ) ,
154
146
DynBenchFn ( Box < TDynBenchFn + ' static > ) ,
155
147
}
156
148
@@ -1337,14 +1329,14 @@ pub fn convert_benchmarks_to_tests(tests: Vec<TestDescAndFn>) -> Vec<TestDescAnd
1337
1329
tests. into_iter ( ) . map ( |x| {
1338
1330
let testfn = match x. testfn {
1339
1331
DynBenchFn ( bench) => {
1340
- DynTestFn ( Box :: new ( move |( ) | {
1332
+ DynTestFn ( Box :: new ( move || {
1341
1333
bench:: run_once ( |b| {
1342
1334
__rust_begin_short_backtrace ( || bench. run ( b) )
1343
1335
} )
1344
1336
} ) )
1345
1337
}
1346
1338
StaticBenchFn ( benchfn) => {
1347
- DynTestFn ( Box :: new ( move |( ) | {
1339
+ DynTestFn ( Box :: new ( move || {
1348
1340
bench:: run_once ( |b| {
1349
1341
__rust_begin_short_backtrace ( || benchfn ( b) )
1350
1342
} )
@@ -1379,7 +1371,7 @@ pub fn run_test(opts: &TestOpts,
1379
1371
fn run_test_inner ( desc : TestDesc ,
1380
1372
monitor_ch : Sender < MonitorMsg > ,
1381
1373
nocapture : bool ,
1382
- testfn : Box < FnBox < ( ) > > ) {
1374
+ testfn : Box < FnBox ( ) + Send > ) {
1383
1375
struct Sink ( Arc < Mutex < Vec < u8 > > > ) ;
1384
1376
impl Write for Sink {
1385
1377
fn write ( & mut self , data : & [ u8 ] ) -> io:: Result < usize > {
@@ -1405,9 +1397,7 @@ pub fn run_test(opts: &TestOpts,
1405
1397
None
1406
1398
} ;
1407
1399
1408
- let result = catch_unwind ( AssertUnwindSafe ( || {
1409
- testfn. call_box ( ( ) )
1410
- } ) ) ;
1400
+ let result = catch_unwind ( AssertUnwindSafe ( testfn) ) ;
1411
1401
1412
1402
if let Some ( ( printio, panicio) ) = oldio {
1413
1403
io:: set_print ( printio) ;
@@ -1449,14 +1439,14 @@ pub fn run_test(opts: &TestOpts,
1449
1439
return ;
1450
1440
}
1451
1441
DynTestFn ( f) => {
1452
- let cb = move |( ) | {
1453
- __rust_begin_short_backtrace ( || f . call_box ( ( ) ) )
1442
+ let cb = move || {
1443
+ __rust_begin_short_backtrace ( f )
1454
1444
} ;
1455
1445
run_test_inner ( desc, monitor_ch, opts. nocapture , Box :: new ( cb) )
1456
1446
}
1457
1447
StaticTestFn ( f) =>
1458
1448
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) ) ) ,
1460
1450
}
1461
1451
}
1462
1452
@@ -1720,7 +1710,7 @@ mod tests {
1720
1710
should_panic : ShouldPanic :: No ,
1721
1711
allow_fail : false ,
1722
1712
} ,
1723
- testfn : DynTestFn ( Box :: new ( move | ( ) | f ( ) ) ) ,
1713
+ testfn : DynTestFn ( Box :: new ( f ) ) ,
1724
1714
} ;
1725
1715
let ( tx, rx) = channel ( ) ;
1726
1716
run_test ( & TestOpts :: new ( ) , false , desc, tx) ;
@@ -1738,7 +1728,7 @@ mod tests {
1738
1728
should_panic : ShouldPanic :: No ,
1739
1729
allow_fail : false ,
1740
1730
} ,
1741
- testfn : DynTestFn ( Box :: new ( move | ( ) | f ( ) ) ) ,
1731
+ testfn : DynTestFn ( Box :: new ( f ) ) ,
1742
1732
} ;
1743
1733
let ( tx, rx) = channel ( ) ;
1744
1734
run_test ( & TestOpts :: new ( ) , false , desc, tx) ;
@@ -1758,7 +1748,7 @@ mod tests {
1758
1748
should_panic : ShouldPanic :: Yes ,
1759
1749
allow_fail : false ,
1760
1750
} ,
1761
- testfn : DynTestFn ( Box :: new ( move | ( ) | f ( ) ) ) ,
1751
+ testfn : DynTestFn ( Box :: new ( f ) ) ,
1762
1752
} ;
1763
1753
let ( tx, rx) = channel ( ) ;
1764
1754
run_test ( & TestOpts :: new ( ) , false , desc, tx) ;
@@ -1778,7 +1768,7 @@ mod tests {
1778
1768
should_panic : ShouldPanic :: YesWithMessage ( "error message" ) ,
1779
1769
allow_fail : false ,
1780
1770
} ,
1781
- testfn : DynTestFn ( Box :: new ( move | ( ) | f ( ) ) ) ,
1771
+ testfn : DynTestFn ( Box :: new ( f ) ) ,
1782
1772
} ;
1783
1773
let ( tx, rx) = channel ( ) ;
1784
1774
run_test ( & TestOpts :: new ( ) , false , desc, tx) ;
@@ -1800,7 +1790,7 @@ mod tests {
1800
1790
should_panic : ShouldPanic :: YesWithMessage ( expected) ,
1801
1791
allow_fail : false ,
1802
1792
} ,
1803
- testfn : DynTestFn ( Box :: new ( move | ( ) | f ( ) ) ) ,
1793
+ testfn : DynTestFn ( Box :: new ( f ) ) ,
1804
1794
} ;
1805
1795
let ( tx, rx) = channel ( ) ;
1806
1796
run_test ( & TestOpts :: new ( ) , false , desc, tx) ;
@@ -1818,7 +1808,7 @@ mod tests {
1818
1808
should_panic : ShouldPanic :: Yes ,
1819
1809
allow_fail : false ,
1820
1810
} ,
1821
- testfn : DynTestFn ( Box :: new ( move | ( ) | f ( ) ) ) ,
1811
+ testfn : DynTestFn ( Box :: new ( f ) ) ,
1822
1812
} ;
1823
1813
let ( tx, rx) = channel ( ) ;
1824
1814
run_test ( & TestOpts :: new ( ) , false , desc, tx) ;
@@ -1852,7 +1842,7 @@ mod tests {
1852
1842
should_panic: ShouldPanic :: No ,
1853
1843
allow_fail: false ,
1854
1844
} ,
1855
- testfn: DynTestFn ( Box :: new( move |( ) | { } ) ) ,
1845
+ testfn: DynTestFn ( Box :: new( move || { } ) ) ,
1856
1846
} ,
1857
1847
TestDescAndFn {
1858
1848
desc: TestDesc {
@@ -1861,7 +1851,7 @@ mod tests {
1861
1851
should_panic: ShouldPanic :: No ,
1862
1852
allow_fail: false ,
1863
1853
} ,
1864
- testfn: DynTestFn ( Box :: new( move |( ) | { } ) ) ,
1854
+ testfn: DynTestFn ( Box :: new( move || { } ) ) ,
1865
1855
} ] ;
1866
1856
let filtered = filter_tests ( & opts, tests) ;
1867
1857
@@ -1885,7 +1875,7 @@ mod tests {
1885
1875
should_panic : ShouldPanic :: No ,
1886
1876
allow_fail : false ,
1887
1877
} ,
1888
- testfn : DynTestFn ( Box :: new ( move |( ) | { } ) )
1878
+ testfn : DynTestFn ( Box :: new ( move || { } ) )
1889
1879
} )
1890
1880
. collect ( )
1891
1881
}
@@ -1967,7 +1957,7 @@ mod tests {
1967
1957
should_panic : ShouldPanic :: No ,
1968
1958
allow_fail : false ,
1969
1959
} ,
1970
- testfn : DynTestFn ( Box :: new ( move | ( ) | testfn ( ) ) ) ,
1960
+ testfn : DynTestFn ( Box :: new ( testfn) ) ,
1971
1961
} ;
1972
1962
tests. push ( test) ;
1973
1963
}
0 commit comments