diff --git a/rayon-core/src/job.rs b/rayon-core/src/job.rs index ac1c6aaf6..cd205990d 100644 --- a/rayon-core/src/job.rs +++ b/rayon-core/src/job.rs @@ -8,7 +8,7 @@ use unwind; pub(super) enum JobResult { None, Ok(T), - Panic(Box), + Panic(Box), } /// A `Job` is used to advertise work for other threads that they may diff --git a/rayon-core/src/join/mod.rs b/rayon-core/src/join/mod.rs index 04d70c095..676fbdfbf 100644 --- a/rayon-core/src/join/mod.rs +++ b/rayon-core/src/join/mod.rs @@ -194,7 +194,7 @@ where unsafe fn join_recover_from_panic( worker_thread: &WorkerThread, job_b_latch: &SpinLatch, - err: Box, + err: Box, ) -> ! { worker_thread.wait_until(job_b_latch); unwind::resume_unwinding(err) diff --git a/rayon-core/src/lib.rs b/rayon-core/src/lib.rs index 5f8d0e971..de87ed523 100644 --- a/rayon-core/src/lib.rs +++ b/rayon-core/src/lib.rs @@ -140,7 +140,7 @@ pub struct ThreadPoolBuilder { panic_handler: Option>, /// Closure to compute the name of a thread. - get_thread_name: Option String>>, + get_thread_name: Option String>>, /// The stack size for the created worker threads stack_size: Option, @@ -170,17 +170,17 @@ pub struct Configuration { /// The type for a panic handling closure. Note that this same closure /// may be invoked multiple times in parallel. -type PanicHandler = Fn(Box) + Send + Sync; +type PanicHandler = dyn Fn(Box) + Send + Sync; /// The type for a closure that gets invoked when a thread starts. The /// closure is passed the index of the thread on which it is invoked. /// Note that this same closure may be invoked multiple times in parallel. -type StartHandler = Fn(usize) + Send + Sync; +type StartHandler = dyn Fn(usize) + Send + Sync; /// The type for a closure that gets invoked when a thread exits. The /// closure is passed the index of the thread on which is is invoked. /// Note that this same closure may be invoked multiple times in parallel. -type ExitHandler = Fn(usize) + Send + Sync; +type ExitHandler = dyn Fn(usize) + Send + Sync; // NB: We can't `#[derive(Default)]` because `S` is left ambiguous. impl Default for ThreadPoolBuilder { @@ -481,7 +481,7 @@ impl ThreadPoolBuilder { /// in a call to `std::panic::catch_unwind()`. pub fn panic_handler(mut self, panic_handler: H) -> Self where - H: Fn(Box) + Send + Sync + 'static, + H: Fn(Box) + Send + Sync + 'static, { self.panic_handler = Some(Box::new(panic_handler)); self @@ -585,7 +585,7 @@ impl Configuration { } /// Deprecated in favor of `ThreadPoolBuilder::build`. - pub fn build(self) -> Result> { + pub fn build(self) -> Result> { self.builder.build().map_err(Box::from) } @@ -607,7 +607,7 @@ impl Configuration { /// Deprecated in favor of `ThreadPoolBuilder::panic_handler`. pub fn panic_handler(mut self, panic_handler: H) -> Configuration where - H: Fn(Box) + Send + Sync + 'static, + H: Fn(Box) + Send + Sync + 'static, { self.builder = self.builder.panic_handler(panic_handler); self @@ -678,7 +678,7 @@ impl fmt::Display for ThreadPoolBuildError { /// Deprecated in favor of `ThreadPoolBuilder::build_global`. #[deprecated(note = "use `ThreadPoolBuilder::build_global`")] #[allow(deprecated)] -pub fn initialize(config: Configuration) -> Result<(), Box> { +pub fn initialize(config: Configuration) -> Result<(), Box> { config.into_builder().build_global().map_err(Box::from) } diff --git a/rayon-core/src/registry.rs b/rayon-core/src/registry.rs index 372fcf3b8..1c43ac8d8 100644 --- a/rayon-core/src/registry.rs +++ b/rayon-core/src/registry.rs @@ -19,7 +19,7 @@ use std::ptr; #[allow(deprecated)] use std::sync::atomic::ATOMIC_USIZE_INIT; use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::{Arc, Once, ONCE_INIT}; +use std::sync::{Arc, Once}; use std::thread; use std::usize; use unwind; @@ -161,7 +161,7 @@ pub(super) struct Registry { /// Initialization static mut THE_REGISTRY: Option<&'static Arc> = None; -static THE_REGISTRY_SET: Once = ONCE_INIT; +static THE_REGISTRY_SET: Once = Once::new(); /// Starts the worker threads (if that has not already happened). If /// initialization has not already occurred, use the default @@ -322,7 +322,7 @@ impl Registry { self.thread_infos.len() } - pub(super) fn handle_panic(&self, err: Box) { + pub(super) fn handle_panic(&self, err: Box) { match self.panic_handler { Some(ref handler) => { // If the customizable panic handler itself panics, diff --git a/rayon-core/src/scope/mod.rs b/rayon-core/src/scope/mod.rs index a797beae0..c3ad5b259 100644 --- a/rayon-core/src/scope/mod.rs +++ b/rayon-core/src/scope/mod.rs @@ -50,7 +50,7 @@ struct ScopeBase<'scope> { /// if some job panicked, the error is stored here; it will be /// propagated to the one who created the scope - panic: AtomicPtr>, + panic: AtomicPtr>, /// latch to set when the counter drops to zero (and hence this scope is complete) job_completed_latch: CountLatch, @@ -59,7 +59,7 @@ struct ScopeBase<'scope> { /// all of which outlive `'scope`. They're not actually required to be /// `Sync`, but it's still safe to let the `Scope` implement `Sync` because /// the closures are only *moved* across threads to be executed. - marker: PhantomData) + Send + Sync + 'scope>>, + marker: PhantomData) + Send + Sync + 'scope>>, } /// Create a "fork-join" scope `s` and invokes the closure with a @@ -572,7 +572,7 @@ impl<'scope> ScopeBase<'scope> { } } - unsafe fn job_panicked(&self, err: Box) { + unsafe fn job_panicked(&self, err: Box) { // capture the first error we see, free the rest let nil = ptr::null_mut(); let mut err = Box::new(err); // box up the fat ptr @@ -613,7 +613,7 @@ impl<'scope> ScopeBase<'scope> { log!(ScopeCompletePanicked { owner_thread: owner_thread.index() }); - let value: Box> = mem::transmute(panic); + let value: Box> = mem::transmute(panic); unwind::resume_unwinding(*value); } else { log!(ScopeCompleteNoPanic { diff --git a/rayon-core/src/spawn/test.rs b/rayon-core/src/spawn/test.rs index 59a9496b8..9b9daab17 100644 --- a/rayon-core/src/spawn/test.rs +++ b/rayon-core/src/spawn/test.rs @@ -27,7 +27,7 @@ fn panic_fwd() { let (tx, rx) = channel(); let tx = Mutex::new(tx); - let panic_handler = move |err: Box| { + let panic_handler = move |err: Box| { let tx = tx.lock().unwrap(); if let Some(&msg) = err.downcast_ref::<&str>() { if msg == "Hello, world!" { @@ -87,7 +87,7 @@ fn custom_panic_handler_and_spawn() { // channel; since the closure is potentially executed in parallel // with itself, we have to wrap `tx` in a mutex. let tx = Mutex::new(tx); - let panic_handler = move |e: Box| { + let panic_handler = move |e: Box| { tx.lock().unwrap().send(e).unwrap(); }; diff --git a/rayon-core/src/thread_pool/mod.rs b/rayon-core/src/thread_pool/mod.rs index 8a1875343..093546ee0 100644 --- a/rayon-core/src/thread_pool/mod.rs +++ b/rayon-core/src/thread_pool/mod.rs @@ -57,7 +57,7 @@ impl ThreadPool { #[deprecated(note = "Use `ThreadPoolBuilder::build`")] #[allow(deprecated)] /// Deprecated in favor of `ThreadPoolBuilder::build`. - pub fn new(configuration: Configuration) -> Result> { + pub fn new(configuration: Configuration) -> Result> { Self::build(configuration.into_builder()).map_err(Box::from) } diff --git a/rayon-core/src/unwind.rs b/rayon-core/src/unwind.rs index fceed410b..9671fa578 100644 --- a/rayon-core/src/unwind.rs +++ b/rayon-core/src/unwind.rs @@ -17,7 +17,7 @@ where panic::catch_unwind(AssertUnwindSafe(func)) } -pub(super) fn resume_unwinding(payload: Box) -> ! { +pub(super) fn resume_unwinding(payload: Box) -> ! { panic::resume_unwind(payload) } diff --git a/rayon-demo/src/tsp/mod.rs b/rayon-demo/src/tsp/mod.rs index d29bdc087..dcb0d2c66 100644 --- a/rayon-demo/src/tsp/mod.rs +++ b/rayon-demo/src/tsp/mod.rs @@ -103,7 +103,7 @@ fn run_solver(datafile: &Path, seq_threshold: usize, from: usize) -> Result<(), Ok(()) } -fn parse_solver(datafile: &Path) -> Result> { +fn parse_solver(datafile: &Path) -> Result> { let mut file = File::open(datafile)?; let mut text = String::new(); file.read_to_string(&mut text)?; diff --git a/src/iter/collect/mod.rs b/src/iter/collect/mod.rs index cab25e86d..21328108b 100644 --- a/src/iter/collect/mod.rs +++ b/src/iter/collect/mod.rs @@ -139,8 +139,8 @@ where // This works like `extend`, but `Vec::append` is more efficient. let list = super::extend::collect(par_iter); self.reserve(super::extend::len(&list)); - for ref mut vec in list { - self.append(vec); + for mut vec in list { + self.append(&mut vec); } } } diff --git a/src/iter/extend.rs b/src/iter/extend.rs index 82221e1ae..9de3ebff3 100644 --- a/src/iter/extend.rs +++ b/src/iter/extend.rs @@ -43,8 +43,8 @@ fn as_list(item: T) -> LinkedList { list } -fn list_append(mut list1: LinkedList, ref mut list2: LinkedList) -> LinkedList { - list1.append(list2); +fn list_append(mut list1: LinkedList, mut list2: LinkedList) -> LinkedList { + list1.append(&mut list2); list1 } diff --git a/src/iter/test.rs b/src/iter/test.rs index d2a6c1dee..b632383f3 100644 --- a/src/iter/test.rs +++ b/src/iter/test.rs @@ -985,7 +985,7 @@ fn check_chunks() { let par_sum_product_triples: i32 = a.par_chunks(3).map(|c| c.iter().product::()).sum(); let seq_sum_product_triples = a.chunks(3).map(|c| c.iter().product::()).sum(); - assert_eq!(par_sum_product_triples, 5_0 + 12_00 + 2_000_0000 + 1); + assert_eq!(par_sum_product_triples, 5_0 + 12_00 + 20_000_000 + 1); assert_eq!(par_sum_product_triples, seq_sum_product_triples); }