Skip to content

Commit b216c3e

Browse files
committed
Update bare traits to dyn Trait
This syntax is available since Rust 1.27.
1 parent 58b0275 commit b216c3e

File tree

9 files changed

+20
-20
lines changed

9 files changed

+20
-20
lines changed

rayon-core/src/job.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use unwind;
88
pub(super) enum JobResult<T> {
99
None,
1010
Ok(T),
11-
Panic(Box<Any + Send>),
11+
Panic(Box<dyn Any + Send>),
1212
}
1313

1414
/// A `Job` is used to advertise work for other threads that they may

rayon-core/src/join/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ where
194194
unsafe fn join_recover_from_panic(
195195
worker_thread: &WorkerThread,
196196
job_b_latch: &SpinLatch,
197-
err: Box<Any + Send>,
197+
err: Box<dyn Any + Send>,
198198
) -> ! {
199199
worker_thread.wait_until(job_b_latch);
200200
unwind::resume_unwinding(err)

rayon-core/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub struct ThreadPoolBuilder<S = DefaultSpawn> {
140140
panic_handler: Option<Box<PanicHandler>>,
141141

142142
/// Closure to compute the name of a thread.
143-
get_thread_name: Option<Box<FnMut(usize) -> String>>,
143+
get_thread_name: Option<Box<dyn FnMut(usize) -> String>>,
144144

145145
/// The stack size for the created worker threads
146146
stack_size: Option<usize>,
@@ -170,17 +170,17 @@ pub struct Configuration {
170170

171171
/// The type for a panic handling closure. Note that this same closure
172172
/// may be invoked multiple times in parallel.
173-
type PanicHandler = Fn(Box<Any + Send>) + Send + Sync;
173+
type PanicHandler = dyn Fn(Box<dyn Any + Send>) + Send + Sync;
174174

175175
/// The type for a closure that gets invoked when a thread starts. The
176176
/// closure is passed the index of the thread on which it is invoked.
177177
/// Note that this same closure may be invoked multiple times in parallel.
178-
type StartHandler = Fn(usize) + Send + Sync;
178+
type StartHandler = dyn Fn(usize) + Send + Sync;
179179

180180
/// The type for a closure that gets invoked when a thread exits. The
181181
/// closure is passed the index of the thread on which is is invoked.
182182
/// Note that this same closure may be invoked multiple times in parallel.
183-
type ExitHandler = Fn(usize) + Send + Sync;
183+
type ExitHandler = dyn Fn(usize) + Send + Sync;
184184

185185
// NB: We can't `#[derive(Default)]` because `S` is left ambiguous.
186186
impl Default for ThreadPoolBuilder {
@@ -481,7 +481,7 @@ impl<S> ThreadPoolBuilder<S> {
481481
/// in a call to `std::panic::catch_unwind()`.
482482
pub fn panic_handler<H>(mut self, panic_handler: H) -> Self
483483
where
484-
H: Fn(Box<Any + Send>) + Send + Sync + 'static,
484+
H: Fn(Box<dyn Any + Send>) + Send + Sync + 'static,
485485
{
486486
self.panic_handler = Some(Box::new(panic_handler));
487487
self
@@ -585,7 +585,7 @@ impl Configuration {
585585
}
586586

587587
/// Deprecated in favor of `ThreadPoolBuilder::build`.
588-
pub fn build(self) -> Result<ThreadPool, Box<Error + 'static>> {
588+
pub fn build(self) -> Result<ThreadPool, Box<dyn Error + 'static>> {
589589
self.builder.build().map_err(Box::from)
590590
}
591591

@@ -607,7 +607,7 @@ impl Configuration {
607607
/// Deprecated in favor of `ThreadPoolBuilder::panic_handler`.
608608
pub fn panic_handler<H>(mut self, panic_handler: H) -> Configuration
609609
where
610-
H: Fn(Box<Any + Send>) + Send + Sync + 'static,
610+
H: Fn(Box<dyn Any + Send>) + Send + Sync + 'static,
611611
{
612612
self.builder = self.builder.panic_handler(panic_handler);
613613
self
@@ -678,7 +678,7 @@ impl fmt::Display for ThreadPoolBuildError {
678678
/// Deprecated in favor of `ThreadPoolBuilder::build_global`.
679679
#[deprecated(note = "use `ThreadPoolBuilder::build_global`")]
680680
#[allow(deprecated)]
681-
pub fn initialize(config: Configuration) -> Result<(), Box<Error>> {
681+
pub fn initialize(config: Configuration) -> Result<(), Box<dyn Error>> {
682682
config.into_builder().build_global().map_err(Box::from)
683683
}
684684

rayon-core/src/registry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl Registry {
322322
self.thread_infos.len()
323323
}
324324

325-
pub(super) fn handle_panic(&self, err: Box<Any + Send>) {
325+
pub(super) fn handle_panic(&self, err: Box<dyn Any + Send>) {
326326
match self.panic_handler {
327327
Some(ref handler) => {
328328
// If the customizable panic handler itself panics,

rayon-core/src/scope/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct ScopeBase<'scope> {
5050

5151
/// if some job panicked, the error is stored here; it will be
5252
/// propagated to the one who created the scope
53-
panic: AtomicPtr<Box<Any + Send + 'static>>,
53+
panic: AtomicPtr<Box<dyn Any + Send + 'static>>,
5454

5555
/// latch to set when the counter drops to zero (and hence this scope is complete)
5656
job_completed_latch: CountLatch,
@@ -59,7 +59,7 @@ struct ScopeBase<'scope> {
5959
/// all of which outlive `'scope`. They're not actually required to be
6060
/// `Sync`, but it's still safe to let the `Scope` implement `Sync` because
6161
/// the closures are only *moved* across threads to be executed.
62-
marker: PhantomData<Box<FnOnce(&Scope<'scope>) + Send + Sync + 'scope>>,
62+
marker: PhantomData<Box<dyn FnOnce(&Scope<'scope>) + Send + Sync + 'scope>>,
6363
}
6464

6565
/// Create a "fork-join" scope `s` and invokes the closure with a
@@ -572,7 +572,7 @@ impl<'scope> ScopeBase<'scope> {
572572
}
573573
}
574574

575-
unsafe fn job_panicked(&self, err: Box<Any + Send + 'static>) {
575+
unsafe fn job_panicked(&self, err: Box<dyn Any + Send + 'static>) {
576576
// capture the first error we see, free the rest
577577
let nil = ptr::null_mut();
578578
let mut err = Box::new(err); // box up the fat ptr
@@ -613,7 +613,7 @@ impl<'scope> ScopeBase<'scope> {
613613
log!(ScopeCompletePanicked {
614614
owner_thread: owner_thread.index()
615615
});
616-
let value: Box<Box<Any + Send + 'static>> = mem::transmute(panic);
616+
let value: Box<Box<dyn Any + Send + 'static>> = mem::transmute(panic);
617617
unwind::resume_unwinding(*value);
618618
} else {
619619
log!(ScopeCompleteNoPanic {

rayon-core/src/spawn/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn panic_fwd() {
2727
let (tx, rx) = channel();
2828

2929
let tx = Mutex::new(tx);
30-
let panic_handler = move |err: Box<Any + Send>| {
30+
let panic_handler = move |err: Box<dyn Any + Send>| {
3131
let tx = tx.lock().unwrap();
3232
if let Some(&msg) = err.downcast_ref::<&str>() {
3333
if msg == "Hello, world!" {
@@ -87,7 +87,7 @@ fn custom_panic_handler_and_spawn() {
8787
// channel; since the closure is potentially executed in parallel
8888
// with itself, we have to wrap `tx` in a mutex.
8989
let tx = Mutex::new(tx);
90-
let panic_handler = move |e: Box<Any + Send>| {
90+
let panic_handler = move |e: Box<dyn Any + Send>| {
9191
tx.lock().unwrap().send(e).unwrap();
9292
};
9393

rayon-core/src/thread_pool/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl ThreadPool {
5757
#[deprecated(note = "Use `ThreadPoolBuilder::build`")]
5858
#[allow(deprecated)]
5959
/// Deprecated in favor of `ThreadPoolBuilder::build`.
60-
pub fn new(configuration: Configuration) -> Result<ThreadPool, Box<Error>> {
60+
pub fn new(configuration: Configuration) -> Result<ThreadPool, Box<dyn Error>> {
6161
Self::build(configuration.into_builder()).map_err(Box::from)
6262
}
6363

rayon-core/src/unwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ where
1717
panic::catch_unwind(AssertUnwindSafe(func))
1818
}
1919

20-
pub(super) fn resume_unwinding(payload: Box<Any + Send>) -> ! {
20+
pub(super) fn resume_unwinding(payload: Box<dyn Any + Send>) -> ! {
2121
panic::resume_unwind(payload)
2222
}
2323

rayon-demo/src/tsp/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn run_solver(datafile: &Path, seq_threshold: usize, from: usize) -> Result<(),
103103
Ok(())
104104
}
105105

106-
fn parse_solver(datafile: &Path) -> Result<Graph, Box<Error>> {
106+
fn parse_solver(datafile: &Path) -> Result<Graph, Box<dyn Error>> {
107107
let mut file = File::open(datafile)?;
108108
let mut text = String::new();
109109
file.read_to_string(&mut text)?;

0 commit comments

Comments
 (0)