Skip to content

Commit

Permalink
ci: enable clippy lints (#1335)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e authored Jul 25, 2019
1 parent f311ac3 commit fe021e6
Show file tree
Hide file tree
Showing 54 changed files with 394 additions and 274 deletions.
6 changes: 6 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ jobs:
rust: $(nightly)
name: rustfmt

# Apply clippy lints to all crates
- template: ci/azure-clippy.yml
parameters:
rust: $(nightly)
name: clippy

# Test top level crate
- template: ci/azure-test-stable.yml
parameters:
Expand Down
16 changes: 16 additions & 0 deletions ci/azure-clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
jobs:
- job: ${{ parameters.name }}
displayName: Clippy
pool:
vmImage: ubuntu-16.04
steps:
- template: azure-install-rust.yml
parameters:
rust_version: ${{ parameters.rust }}
- script: |
rustup component add clippy
cargo clippy --version
displayName: Install clippy
- script: |
cargo clippy --all --all-features -- -D warnings -A clippy::mutex-atomic
displayName: cargo clippy --all
4 changes: 2 additions & 2 deletions tokio-codec/src/bytes_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bytes::{BufMut, Bytes, BytesMut};
use std::io;

/// A simple `Codec` implementation that just ships bytes around.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
pub struct BytesCodec(());

impl BytesCodec {
Expand All @@ -19,7 +19,7 @@ impl Decoder for BytesCodec {
type Error = io::Error;

fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<BytesMut>, io::Error> {
if buf.len() > 0 {
if !buf.is_empty() {
let len = buf.len();
Ok(Some(buf.split_to(len)))
} else {
Expand Down
2 changes: 1 addition & 1 deletion tokio-codec/src/framed_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub fn framed_read2_with_buffer<T>(inner: T, mut buf: BytesMut) -> FramedRead2<T
FramedRead2 {
inner,
eof: false,
is_readable: buf.len() > 0,
is_readable: !buf.is_empty(),
buffer: buf,
}
}
Expand Down
6 changes: 6 additions & 0 deletions tokio-codec/src/lines_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ impl Encoder for LinesCodec {
}
}

impl Default for LinesCodec {
fn default() -> Self {
Self::new()
}
}

/// An error occured while encoding or decoding a line.
#[derive(Debug)]
pub enum LinesCodecError {
Expand Down
16 changes: 12 additions & 4 deletions tokio-current-thread/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ impl<P: Park> CurrentThread<P> {
}

/// Bind `CurrentThread` instance with an execution context.
fn enter<'a>(&'a mut self) -> Entered<'a, P> {
fn enter(&mut self) -> Entered<'_, P> {
Entered { executor: self }
}

Expand Down Expand Up @@ -429,6 +429,12 @@ impl<P: Park> fmt::Debug for CurrentThread<P> {
}
}

impl<P: Park + Default> Default for CurrentThread<P> {
fn default() -> Self {
CurrentThread::new_with_park(P::default())
}
}

// ===== impl Entered =====

impl<'a, P: Park> Entered<'a, P> {
Expand Down Expand Up @@ -483,7 +489,7 @@ impl<'a, P: Park> Entered<'a, P> {

self.tick();

if let Err(_) = self.executor.park.park() {
if self.executor.park.park().is_err() {
panic!("block_on park failed");
}
}
Expand Down Expand Up @@ -550,7 +556,7 @@ impl<'a, P: Park> Entered<'a, P> {

match time {
Some((until, rem)) => {
if let Err(_) = self.executor.park.park_timeout(rem) {
if self.executor.park.park_timeout(rem).is_err() {
return Err(RunTimeoutError::new(false));
}

Expand All @@ -563,7 +569,7 @@ impl<'a, P: Park> Entered<'a, P> {
time = Some((until, until - now));
}
None => {
if let Err(_) = self.executor.park.park() {
if self.executor.park.park().is_err() {
return Err(RunTimeoutError::new(false));
}
}
Expand Down Expand Up @@ -790,6 +796,8 @@ impl CurrentRunner {

unsafe fn hide_lt<'a>(p: *mut (dyn SpawnLocal + 'a)) -> *mut (dyn SpawnLocal + 'static) {
use std::mem;
// false positive: https://github.com/rust-lang/rust-clippy/issues/2906
#[allow(clippy::transmute_ptr_to_ptr)]
mem::transmute(p)
}

Expand Down
12 changes: 5 additions & 7 deletions tokio-current-thread/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,8 @@ impl<U> Inner<U> {
let tail = *self.tail_readiness.get();
let next = (*tail).next_readiness.load(Acquire);

if tail == self.stub() {
if next.is_null() {
return false;
}
if tail == self.stub() && next.is_null() {
return false;
}

true
Expand Down Expand Up @@ -566,7 +564,7 @@ impl<U> List<U> {

self.len += 1;

return ptr;
ptr
}

/// Pop an element from the front of the list
Expand Down Expand Up @@ -618,7 +616,7 @@ impl<U> List<U> {

self.len -= 1;

return node;
node
}
}

Expand Down Expand Up @@ -773,7 +771,7 @@ impl<U> Drop for Node<U> {
fn arc2ptr<T>(ptr: Arc<T>) -> *const T {
let addr = &*ptr as *const T;
mem::forget(ptr);
return addr;
addr
}

unsafe fn ptr2arc<T>(ptr: *const T) -> Arc<T> {
Expand Down
2 changes: 2 additions & 0 deletions tokio-executor/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ where

unsafe fn hide_lt<'a>(p: *mut (dyn Executor + 'a)) -> *mut (dyn Executor + 'static) {
use std::mem;
// false positive: https://github.com/rust-lang/rust-clippy/issues/2906
#[allow(clippy::transmute_ptr_to_ptr)]
mem::transmute(p)
}

Expand Down
6 changes: 6 additions & 0 deletions tokio-executor/src/park.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ impl Park for ParkThread {
}
}

impl Default for ParkThread {
fn default() -> Self {
Self::new()
}
}

// ===== impl UnparkThread =====

impl Unpark for UnparkThread {
Expand Down
6 changes: 6 additions & 0 deletions tokio-fs/src/file/open_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ impl From<StdOpenOptions> for OpenOptions {
OpenOptions(options)
}
}

impl Default for OpenOptions {
fn default() -> Self {
Self::new()
}
}
4 changes: 2 additions & 2 deletions tokio-io/src/async_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ pub trait AsyncRead {
/// [`io::Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
/// [`poll_read_buf`]: #method.poll_read_buf
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
for i in 0..buf.len() {
buf[i] = 0;
for x in buf {
*x = 0;
}

true
Expand Down
13 changes: 5 additions & 8 deletions tokio-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,12 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
let mut runtime = RuntimeType::Multi;

for arg in args {
match arg {
syn::NestedMeta::Meta(syn::Meta::Word(ident)) => {
match ident.to_string().to_lowercase().as_str() {
"multi_thread" => runtime = RuntimeType::Multi,
"single_thread" => runtime = RuntimeType::Single,
name => panic!("Unknown attribute {} is specified", name),
}
if let syn::NestedMeta::Meta(syn::Meta::Word(ident)) = arg {
match ident.to_string().to_lowercase().as_str() {
"multi_thread" => runtime = RuntimeType::Multi,
"single_thread" => runtime = RuntimeType::Single,
name => panic!("Unknown attribute {} is specified", name),
}
_ => (),
}
}

Expand Down
14 changes: 7 additions & 7 deletions tokio-reactor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl Reactor {
"loop process - {} events, {}.{:03}s",
events,
dur.as_secs(),
dur.subsec_nanos() / 1_000_000
dur.subsec_millis()
);
}

Expand Down Expand Up @@ -352,7 +352,7 @@ impl Reactor {

io.readiness.fetch_or(ready.as_usize(), Relaxed);

if ready.is_writable() || platform::is_hup(&ready) {
if ready.is_writable() || platform::is_hup(ready) {
wr = io.writer.take_waker();
}

Expand Down Expand Up @@ -570,8 +570,8 @@ impl Drop for Inner {
}

impl Direction {
fn mask(&self) -> mio::Ready {
match *self {
fn mask(self) -> mio::Ready {
match self {
Direction::Read => {
// Everything except writable is signaled through read.
mio::Ready::all() - mio::Ready::writable()
Expand All @@ -590,8 +590,8 @@ mod platform {
UnixReady::hup().into()
}

pub fn is_hup(ready: &Ready) -> bool {
UnixReady::from(*ready).is_hup()
pub fn is_hup(ready: Ready) -> bool {
UnixReady::from(ready).is_hup()
}
}

Expand All @@ -603,7 +603,7 @@ mod platform {
Ready::empty()
}

pub fn is_hup(_: &Ready) -> bool {
pub fn is_hup(_: Ready) -> bool {
false
}
}
2 changes: 1 addition & 1 deletion tokio-reactor/src/poll_evented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ where
// Cannot clear write readiness
assert!(!ready.is_writable(), "cannot clear write readiness");
assert!(
!crate::platform::is_hup(&ready),
!crate::platform::is_hup(ready),
"cannot clear HUP readiness"
);

Expand Down
8 changes: 7 additions & 1 deletion tokio-reactor/src/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl Registration {
where
T: Evented,
{
self.register2(io, || HandlePriv::try_current())
self.register2(io, HandlePriv::try_current)
}

/// Deregister the I/O resource from the reactor it is associated with.
Expand Down Expand Up @@ -416,6 +416,12 @@ impl Registration {
}
}

impl Default for Registration {
fn default() -> Self {
Self::new()
}
}

unsafe impl Send for Registration {}
unsafe impl Sync for Registration {}

Expand Down
6 changes: 3 additions & 3 deletions tokio-signal/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ impl<S: Storage> Registry<S> {
/// Mark `event_id` as having been delivered, without broadcasting it to
/// any listeners.
fn record_event(&self, event_id: EventId) {
self.storage
.event_info(event_id)
.map(|event_info| event_info.pending.store(true, Ordering::SeqCst));
if let Some(event_info) = self.storage.event_info(event_id) {
event_info.pending.store(true, Ordering::SeqCst)
}
}

/// Broadcast all previously recorded events to their respective listeners.
Expand Down
2 changes: 2 additions & 0 deletions tokio-sync/src/mpsc/bounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl<T> Receiver<T> {
}

/// TODO: Dox
#[allow(clippy::needless_lifetimes)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3988
pub async fn recv(&mut self) -> Option<T> {
use async_util::future::poll_fn;

Expand Down Expand Up @@ -204,6 +205,7 @@ impl<T> Sender<T> {
/// ```
/// unimplemented!();
/// ```
#[allow(clippy::needless_lifetimes)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3988
pub async fn send(&mut self, value: T) -> Result<(), SendError> {
use async_util::future::poll_fn;

Expand Down
1 change: 1 addition & 0 deletions tokio-sync/src/mpsc/unbounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl<T> UnboundedReceiver<T> {
}

/// TODO: Dox
#[allow(clippy::needless_lifetimes)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3988
pub async fn recv(&mut self) -> Option<T> {
use async_util::future::poll_fn;

Expand Down
Loading

0 comments on commit fe021e6

Please sign in to comment.