ci: enable clippy lints (#1335)

This commit is contained in:
Taiki Endo
2019-07-26 03:47:14 +09:00
committed by GitHub
parent f311ac3d4f
commit fe021e6c00
54 changed files with 394 additions and 274 deletions
+6
View File
@@ -420,3 +420,9 @@ impl fmt::Debug for Builder {
.finish()
}
}
impl Default for Builder {
fn default() -> Self {
Self::new()
}
}
+4 -1
View File
@@ -14,9 +14,12 @@ pub(crate) struct Config {
pub around_worker: Option<Callback>,
pub after_start: Option<Arc<dyn Fn() + Send + Sync>>,
pub before_stop: Option<Arc<dyn Fn() + Send + Sync>>,
pub panic_handler: Option<Arc<dyn Fn(Box<dyn Any + Send>) + Send + Sync>>,
pub panic_handler: Option<PanicHandler>,
}
// Define type alias to avoid clippy::type_complexity.
type PanicHandler = Arc<dyn Fn(Box<dyn Any + Send>) + Send + Sync>;
/// Max number of workers that can be part of a pool. This is the most that can
/// fit in the scheduler state. Note, that this is the max number of **active**
/// threads. There can be more standby threads.
@@ -72,6 +72,12 @@ impl Park for DefaultPark {
}
}
impl Default for DefaultPark {
fn default() -> Self {
Self::new()
}
}
// ===== impl DefaultUnpark =====
impl Unpark for DefaultUnpark {
+6 -6
View File
@@ -235,12 +235,12 @@ impl Backup {
impl State {
/// Returns a new, default, thread `State`
pub fn new() -> State {
pub(crate) fn new() -> State {
State(0)
}
/// Returns true if the thread entry is pushed in the sleeper stack
pub fn is_pushed(&self) -> bool {
pub(crate) fn is_pushed(self) -> bool {
self.0 & PUSHED == PUSHED
}
@@ -248,19 +248,19 @@ impl State {
self.0 &= !PUSHED;
}
pub fn is_running(&self) -> bool {
pub(crate) fn is_running(self) -> bool {
self.0 & RUNNING == RUNNING
}
pub fn set_running(&mut self) {
pub(crate) fn set_running(&mut self) {
self.0 |= RUNNING;
}
pub fn unset_running(&mut self) {
pub(crate) fn unset_running(&mut self) {
self.0 &= !RUNNING;
}
pub fn is_terminated(&self) -> bool {
pub(crate) fn is_terminated(self) -> bool {
self.0 & TERMINATED == TERMINATED
}
+2 -5
View File
@@ -93,10 +93,7 @@ impl BackupStack {
/// * `Err(_)` is returned if the pool has been shutdown.
pub fn pop(&self, entries: &[Backup], terminate: bool) -> Result<Option<BackupId>, ()> {
// Figure out the empty value
let terminal = match terminate {
true => TERMINATED,
false => EMPTY,
};
let terminal = if terminate { TERMINATED } else { EMPTY };
let mut state: State = self.state.load(Acquire).into();
@@ -164,7 +161,7 @@ impl State {
State(EMPTY.0)
}
fn head(&self) -> BackupId {
fn head(self) -> BackupId {
BackupId(self.0 & STACK_MASK)
}
+9 -9
View File
@@ -33,19 +33,19 @@ pub(crate) const MAX_FUTURES: usize = usize::MAX >> NUM_FUTURES_OFFSET;
impl State {
#[inline]
pub fn new() -> State {
pub(crate) fn new() -> State {
State(0)
}
/// Returns the number of futures still pending completion.
pub fn num_futures(&self) -> usize {
pub(crate) fn num_futures(self) -> usize {
self.0 >> NUM_FUTURES_OFFSET
}
/// Increment the number of futures pending completion.
///
/// Returns false on failure.
pub fn inc_num_futures(&mut self) {
pub(crate) fn inc_num_futures(&mut self) {
debug_assert!(self.num_futures() < MAX_FUTURES);
debug_assert!(self.lifecycle() < Lifecycle::ShutdownNow);
@@ -53,7 +53,7 @@ impl State {
}
/// Decrement the number of futures pending completion.
pub fn dec_num_futures(&mut self) {
pub(crate) fn dec_num_futures(&mut self) {
let num_futures = self.num_futures();
if num_futures == 0 {
@@ -69,19 +69,19 @@ impl State {
}
/// Set the number of futures pending completion to zero
pub fn clear_num_futures(&mut self) {
self.0 = self.0 & LIFECYCLE_MASK;
pub(crate) fn clear_num_futures(&mut self) {
self.0 &= LIFECYCLE_MASK;
}
pub fn lifecycle(&self) -> Lifecycle {
pub(crate) fn lifecycle(self) -> Lifecycle {
(self.0 & LIFECYCLE_MASK).into()
}
pub fn set_lifecycle(&mut self, val: Lifecycle) {
pub(crate) fn set_lifecycle(&mut self, val: Lifecycle) {
self.0 = (self.0 & NUM_FUTURES_MASK) | (val as usize);
}
pub fn is_terminated(&self) -> bool {
pub(crate) fn is_terminated(self) -> bool {
self.lifecycle() == Lifecycle::ShutdownNow && self.num_futures() == 0
}
}
+6 -6
View File
@@ -393,7 +393,7 @@ impl State {
State((capacity << NUM_SHIFT) | NUM_FLAG)
}
fn remaining_capacity(&self) -> usize {
fn remaining_capacity(self) -> usize {
if !self.has_remaining_capacity() {
return 0;
}
@@ -401,15 +401,15 @@ impl State {
self.0 >> 1
}
fn has_remaining_capacity(&self) -> bool {
fn has_remaining_capacity(self) -> bool {
self.0 & NUM_FLAG == NUM_FLAG
}
fn has_task(&self, stub: &Task) -> bool {
fn has_task(self, stub: &Task) -> bool {
!(self.has_remaining_capacity() || self.is_stub(stub))
}
fn is_stub(&self, stub: &Task) -> bool {
fn is_stub(self, stub: &Task) -> bool {
self.0 == stub as *const _ as usize
}
@@ -452,11 +452,11 @@ impl State {
}
}
fn is_ptr(&self) -> bool {
fn is_ptr(self) -> bool {
self.0 & NUM_FLAG == 0
}
fn ptr(&self) -> Option<*const Task> {
fn ptr(self) -> Option<*const Task> {
if self.is_ptr() {
Some(self.0 as *const Task)
} else {
+6 -6
View File
@@ -18,26 +18,26 @@ const ALLOCATED: usize = 0b10;
impl BlockingState {
/// Create a new, default, `BlockingState`.
pub fn new() -> BlockingState {
pub(crate) fn new() -> BlockingState {
BlockingState(0)
}
/// Returns `true` if the state represents the associated task being queued
/// in the pending blocking capacity channel
pub fn is_queued(&self) -> bool {
pub(crate) fn is_queued(&self) -> bool {
self.0 & QUEUED == QUEUED
}
/// Toggle the queued flag
///
/// Returns the state before the flag has been toggled.
pub fn toggle_queued(state: &AtomicUsize, ordering: Ordering) -> BlockingState {
pub(crate) fn toggle_queued(state: &AtomicUsize, ordering: Ordering) -> BlockingState {
state.fetch_xor(QUEUED, ordering).into()
}
/// Returns `true` if the state represents the associated task having been
/// allocated capacity to block.
pub fn is_allocated(&self) -> bool {
pub(crate) fn is_allocated(&self) -> bool {
self.0 & ALLOCATED == ALLOCATED
}
@@ -46,7 +46,7 @@ impl BlockingState {
///
/// If this returns `true`, then the task has the ability to block for the
/// duration of the `poll`.
pub fn consume_allocation(state: &AtomicUsize, ordering: Ordering) -> CanBlock {
pub(crate) fn consume_allocation(state: &AtomicUsize, ordering: Ordering) -> CanBlock {
let state: Self = state.fetch_and(!ALLOCATED, ordering).into();
if state.is_allocated() {
@@ -58,7 +58,7 @@ impl BlockingState {
}
}
pub fn notify_blocking(state: &AtomicUsize, ordering: Ordering) {
pub(crate) fn notify_blocking(state: &AtomicUsize, ordering: Ordering) {
let prev: Self = state.fetch_xor(ALLOCATED | QUEUED, ordering).into();
debug_assert!(prev.is_queued());
+3 -3
View File
@@ -134,12 +134,12 @@ impl Task {
let mut g = Guard(fut, true);
let mut waker = arc_waker::waker(Arc::new(Waker {
let waker = arc_waker::waker(Arc::new(Waker {
task: me.clone(),
pool: pool.clone(),
}));
let mut cx = Context::from_waker(&mut waker);
let mut cx = Context::from_waker(&waker);
let ret = g.0.as_mut().unwrap().as_mut().poll(&mut cx);
@@ -239,7 +239,7 @@ impl Task {
pub fn schedule(me: &Arc<Self>, pool: &Arc<Pool>) {
if me.schedule2() {
let task = me.clone();
let _ = pool.submit(task, &pool);
pool.submit(task, &pool);
}
}
+2 -2
View File
@@ -27,11 +27,11 @@ impl State {
///
/// Tasks start in the scheduled state as they are immediately scheduled on
/// creation.
pub fn new() -> State {
pub(crate) fn new() -> State {
State::Scheduled
}
pub fn stub() -> State {
pub(crate) fn stub() -> State {
State::Idle
}
}
+6
View File
@@ -198,6 +198,12 @@ impl Drop for ThreadPool {
}
}
impl Default for ThreadPool {
fn default() -> Self {
Self::new()
}
}
/*
* TODO: Bring back
+1 -1
View File
@@ -622,7 +622,7 @@ impl Worker {
// We obtained permission to push the worker into the
// sleeper queue.
if let Err(_) = self.pool.push_sleeper(self.id.0) {
if self.pool.push_sleeper(self.id.0).is_err() {
trace!(" sleeping -- push to stack failed; idx={}", self.id.0);
// The push failed due to the pool being terminated.
//
+2 -5
View File
@@ -120,10 +120,7 @@ impl Stack {
terminate: bool,
) -> Option<(usize, worker::State)> {
// Figure out the empty value
let terminal = match terminate {
true => TERMINATED,
false => EMPTY,
};
let terminal = if terminate { TERMINATED } else { EMPTY };
// If terminating, the max lifecycle *must* be `Signaled`, which is the
// highest lifecycle. By passing the greatest possible lifecycle value,
@@ -215,7 +212,7 @@ impl State {
}
#[inline]
fn head(&self) -> usize {
fn head(self) -> usize {
self.0 & STACK_MASK
}
+4 -4
View File
@@ -35,7 +35,7 @@ pub(crate) enum Lifecycle {
impl State {
/// Returns true if the worker entry is pushed in the sleeper stack
pub fn is_pushed(&self) -> bool {
pub fn is_pushed(self) -> bool {
self.0 & PUSHED_MASK == PUSHED_MASK
}
@@ -43,7 +43,7 @@ impl State {
self.0 |= PUSHED_MASK
}
pub fn is_notified(&self) -> bool {
pub fn is_notified(self) -> bool {
use self::Lifecycle::*;
match self.lifecycle() {
@@ -52,7 +52,7 @@ impl State {
}
}
pub fn lifecycle(&self) -> Lifecycle {
pub fn lifecycle(self) -> Lifecycle {
Lifecycle::from(self.0 & LIFECYCLE_MASK)
}
@@ -60,7 +60,7 @@ impl State {
self.0 = (self.0 & !LIFECYCLE_MASK) | (val as usize)
}
pub fn is_signaled(&self) -> bool {
pub fn is_signaled(self) -> bool {
self.lifecycle() == Lifecycle::Signaled
}