Skip to content

Commit 3c3115a

Browse files
committed
Address many clippy warnings
1 parent d083469 commit 3c3115a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+193
-321
lines changed

rayon-core/src/job.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,9 @@ impl JobRef {
4848
let fn_ptr: unsafe fn(*const T) = <T as Job>::execute;
4949

5050
// erase types:
51-
let fn_ptr: unsafe fn(*const ()) = mem::transmute(fn_ptr);
52-
let pointer = data as *const ();
53-
5451
JobRef {
55-
pointer: pointer,
56-
execute_fn: fn_ptr,
52+
pointer: data as *const (),
53+
execute_fn: mem::transmute(fn_ptr),
5754
}
5855
}
5956

@@ -86,7 +83,7 @@ where
8683
{
8784
pub fn new(func: F, latch: L) -> StackJob<L, F, R> {
8885
StackJob {
89-
latch: latch,
86+
latch,
9087
func: UnsafeCell::new(Some(func)),
9188
result: UnsafeCell::new(JobResult::None),
9289
}

rayon-core/src/join/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ where
171171
}
172172
}
173173

174-
return (result_a, job_b.into_result());
174+
(result_a, job_b.into_result())
175175
})
176176
}
177177

rayon-core/src/latch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'a, L: Latch> TickleLatch<'a, L> {
167167
pub fn new(latch: L, sleep: &'a Sleep) -> Self {
168168
TickleLatch {
169169
inner: latch,
170-
sleep: sleep,
170+
sleep,
171171
}
172172
}
173173
}

rayon-core/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl Configuration {
405405

406406
/// Deprecated in favor of `ThreadPoolBuilder::build`.
407407
pub fn build(self) -> Result<ThreadPool, Box<Error + 'static>> {
408-
self.builder.build().map_err(|e| e.into())
408+
self.builder.build().map_err(Box::from)
409409
}
410410

411411
/// Deprecated in favor of `ThreadPoolBuilder::thread_name`.
@@ -470,7 +470,7 @@ impl Configuration {
470470

471471
impl ThreadPoolBuildError {
472472
fn new(kind: ErrorKind) -> ThreadPoolBuildError {
473-
ThreadPoolBuildError { kind: kind }
473+
ThreadPoolBuildError { kind }
474474
}
475475
}
476476

@@ -498,7 +498,7 @@ impl fmt::Display for ThreadPoolBuildError {
498498
#[deprecated(note = "use `ThreadPoolBuilder::build_global`")]
499499
#[allow(deprecated)]
500500
pub fn initialize(config: Configuration) -> Result<(), Box<Error>> {
501-
config.into_builder().build_global().map_err(|e| e.into())
501+
config.into_builder().build_global().map_err(Box::from)
502502
}
503503

504504
impl fmt::Debug for ThreadPoolBuilder {
@@ -567,7 +567,7 @@ impl FnContext {
567567
#[inline]
568568
fn new(migrated: bool) -> Self {
569569
FnContext {
570-
migrated: migrated,
570+
migrated,
571571
_marker: PhantomData,
572572
}
573573
}

rayon-core/src/registry.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::cell::Cell;
1313
use std::collections::hash_map::DefaultHasher;
1414
use std::hash::Hasher;
1515
use std::mem;
16+
use std::ptr;
1617
#[allow(deprecated)]
1718
use std::sync::atomic::ATOMIC_USIZE_INIT;
1819
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -113,7 +114,7 @@ impl Registry {
113114
.unzip();
114115

115116
let registry = Arc::new(Registry {
116-
thread_infos: stealers.into_iter().map(|s| ThreadInfo::new(s)).collect(),
117+
thread_infos: stealers.into_iter().map(ThreadInfo::new).collect(),
117118
sleep: Sleep::new(),
118119
injected_jobs: SegQueue::new(),
119120
terminate_latch: CountLatch::new(),
@@ -462,7 +463,7 @@ impl ThreadInfo {
462463
ThreadInfo {
463464
primed: LockLatch::new(),
464465
stopped: LockLatch::new(),
465-
stealer: stealer,
466+
stealer,
466467
}
467468
}
468469
}
@@ -491,8 +492,7 @@ pub struct WorkerThread {
491492
// worker is fully unwound. Using an unsafe pointer avoids the need
492493
// for a RefCell<T> etc.
493494
thread_local! {
494-
static WORKER_THREAD_STATE: Cell<*const WorkerThread> =
495-
Cell::new(0 as *const WorkerThread)
495+
static WORKER_THREAD_STATE: Cell<*const WorkerThread> = Cell::new(ptr::null());
496496
}
497497

498498
impl WorkerThread {
@@ -501,7 +501,7 @@ impl WorkerThread {
501501
/// anywhere on the current thread.
502502
#[inline]
503503
pub fn current() -> *const WorkerThread {
504-
WORKER_THREAD_STATE.with(|t| t.get())
504+
WORKER_THREAD_STATE.with(Cell::get)
505505
}
506506

507507
/// Sets `self` as the worker thread index for the current thread.
@@ -654,9 +654,9 @@ impl WorkerThread {
654654
655655
unsafe fn main_loop(worker: Worker<JobRef>, registry: Arc<Registry>, index: usize) {
656656
let worker_thread = WorkerThread {
657-
worker: worker,
657+
worker,
658658
fifo: JobFifo::new(),
659-
index: index,
659+
index,
660660
rng: XorShift64Star::new(),
661661
registry: registry.clone(),
662662
};

rayon-core/src/thread_pool/internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl ThreadPoolScopeHandle {
3131
/// Caller asserts that the registry has not yet terminated.
3232
unsafe fn new(registry: Arc<Registry>) -> Self {
3333
registry.increment_terminate_count();
34-
ThreadPoolScopeHandle { registry: registry }
34+
ThreadPoolScopeHandle { registry }
3535
}
3636
}
3737

rayon-core/src/thread_pool/mod.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ pub struct ThreadPool {
5555

5656
pub fn build(builder: ThreadPoolBuilder) -> Result<ThreadPool, ThreadPoolBuildError> {
5757
let registry = try!(Registry::new(builder));
58-
Ok(ThreadPool { registry: registry })
58+
Ok(ThreadPool { registry })
5959
}
6060

6161
impl ThreadPool {
6262
#[deprecated(note = "Use `ThreadPoolBuilder::build`")]
6363
#[allow(deprecated)]
6464
/// Deprecated in favor of `ThreadPoolBuilder::build`.
6565
pub fn new(configuration: Configuration) -> Result<ThreadPool, Box<Error>> {
66-
build(configuration.into_builder()).map_err(|e| e.into())
66+
build(configuration.into_builder()).map_err(Box::from)
6767
}
6868

6969
/// Returns a handle to the global thread pool. This is the pool
@@ -166,13 +166,11 @@ impl ThreadPool {
166166
#[inline]
167167
pub fn current_thread_index(&self) -> Option<usize> {
168168
unsafe {
169-
let curr = WorkerThread::current();
170-
if curr.is_null() {
171-
None
172-
} else if (*curr).registry().id() != self.registry.id() {
173-
None
169+
let curr = WorkerThread::current().as_ref()?;
170+
if curr.registry().id() == self.registry.id() {
171+
Some(curr.index())
174172
} else {
175-
Some((*curr).index())
173+
None
176174
}
177175
}
178176
}
@@ -201,13 +199,11 @@ impl ThreadPool {
201199
#[inline]
202200
pub fn current_thread_has_pending_tasks(&self) -> Option<bool> {
203201
unsafe {
204-
let curr = WorkerThread::current();
205-
if curr.is_null() {
206-
None
207-
} else if (*curr).registry().id() != self.registry.id() {
208-
None
209-
} else {
202+
let curr = WorkerThread::current().as_ref()?;
203+
if curr.registry().id() == self.registry.id() {
210204
Some(!(*curr).local_deque_is_empty())
205+
} else {
206+
None
211207
}
212208
}
213209
}

src/iter/chain.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ where
2828
A: ParallelIterator,
2929
B: ParallelIterator<Item = A::Item>,
3030
{
31-
Chain { a: a, b: b }
31+
Chain { a, b }
3232
}
3333

3434
impl<A, B> ParallelIterator for Chain<A, B>
@@ -92,8 +92,8 @@ where
9292
{
9393
let a_len = self.a.len();
9494
return self.a.with_producer(CallbackA {
95-
callback: callback,
96-
a_len: a_len,
95+
callback,
96+
a_len,
9797
b: self.b,
9898
});
9999

@@ -114,11 +114,11 @@ where
114114
where
115115
A: Producer<Item = B::Item>,
116116
{
117-
return self.b.with_producer(CallbackB {
117+
self.b.with_producer(CallbackB {
118118
callback: self.callback,
119119
a_len: self.a_len,
120-
a_producer: a_producer,
121-
});
120+
a_producer,
121+
})
122122
}
123123
}
124124

@@ -164,11 +164,7 @@ where
164164
B: Producer<Item = A::Item>,
165165
{
166166
fn new(a_len: usize, a: A, b: B) -> Self {
167-
ChainProducer {
168-
a_len: a_len,
169-
a: a,
170-
b: b,
171-
}
167+
ChainProducer { a_len, a, b }
172168
}
173169
}
174170

src/iter/chunks.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn new<I>(i: I, size: usize) -> Chunks<I>
2727
where
2828
I: IndexedParallelIterator,
2929
{
30-
Chunks { i: i, size: size }
30+
Chunks { i, size }
3131
}
3232

3333
impl<I> ParallelIterator for Chunks<I>
@@ -70,8 +70,8 @@ where
7070
let len = self.i.len();
7171
return self.i.with_producer(Callback {
7272
size: self.size,
73-
len: len,
74-
callback: callback,
73+
len,
74+
callback,
7575
});
7676

7777
struct Callback<CB> {
@@ -93,7 +93,7 @@ where
9393
self.callback.callback(ChunkProducer {
9494
chunk_size: self.size,
9595
len: self.len,
96-
base: base,
96+
base,
9797
})
9898
}
9999
}

src/iter/cloned.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn new<I>(base: I) -> Cloned<I>
2222
where
2323
I: ParallelIterator,
2424
{
25-
Cloned { base: base }
25+
Cloned { base }
2626
}
2727

2828
impl<'a, T, I> ParallelIterator for Cloned<I>
@@ -66,7 +66,7 @@ where
6666
where
6767
CB: ProducerCallback<Self::Item>,
6868
{
69-
return self.base.with_producer(Callback { callback: callback });
69+
return self.base.with_producer(Callback { callback });
7070

7171
struct Callback<CB> {
7272
callback: CB,
@@ -83,7 +83,7 @@ where
8383
where
8484
P: Producer<Item = &'a T>,
8585
{
86-
let producer = ClonedProducer { base: base };
86+
let producer = ClonedProducer { base };
8787
self.callback.callback(producer)
8888
}
8989
}
@@ -141,7 +141,7 @@ struct ClonedConsumer<C> {
141141

142142
impl<C> ClonedConsumer<C> {
143143
fn new(base: C) -> Self {
144-
ClonedConsumer { base: base }
144+
ClonedConsumer { base }
145145
}
146146
}
147147

0 commit comments

Comments
 (0)