Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: enable clippy lints #1335

Merged
merged 25 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d464253
ci: enable clippy lints
taiki-e Jul 20, 2019
cd543bf
Allow some clippy warnings
taiki-e Jul 20, 2019
0cdc174
Fix clippy warnings
taiki-e Jul 20, 2019
c20c23d
cargo fmt --all
taiki-e Jul 21, 2019
063c4d2
Remove default impls to private type added by 0cdc174
taiki-e Jul 20, 2019
9761168
Allow clippy::cast_ptr_alignment warnings
taiki-e Jul 21, 2019
85addd5
Revert "Allow clippy::cast_ptr_alignment warnings"
taiki-e Jul 21, 2019
eb4d80a
Bump to newer nightly
taiki-e Jul 21, 2019
4191092
Use nightly-2019-07-17
taiki-e Jul 21, 2019
2b9ab4f
Merge branch 'master' into ci-clippy
taiki-e Jul 21, 2019
f549d8b
Move allow(clippy::trivially_copy_pass_by_ref) from crate to items
taiki-e Jul 22, 2019
cf79f7c
Move allow(clippy::mutex_atomic) from module to items
taiki-e Jul 22, 2019
f210250
timer: move contents of clock/clock.rs into clock/mod.rs
taiki-e Jul 22, 2019
d63fc9c
sync: change the argument of WaiterNode::into_non_null to `self: Arc<…
taiki-e Jul 22, 2019
b694a3b
timer: change Entry::time_mut to unsafe fn
taiki-e Jul 22, 2019
b5c8e69
allow clippy::mut_from_ref and clippy::wrong_self_convention
taiki-e Jul 22, 2019
56a7c33
threadpool: fix clippy::type_complexity
taiki-e Jul 22, 2019
edca75d
remove unnecessary code
taiki-e Jul 22, 2019
2baee47
add a comment
taiki-e Jul 22, 2019
ae3bd60
allow clippy::mutex_atomic at the project level
taiki-e Jul 24, 2019
3a9fa19
Merge branch 'master' into ci-clippy
taiki-e Jul 24, 2019
614aa54
fix most of clippy::trivially_copy_pass_by_ref
taiki-e Jul 24, 2019
2a05364
fix more
taiki-e Jul 24, 2019
9c5cd86
Merge branch 'master' into ci-clippy
taiki-e Jul 25, 2019
2035f15
Merge branch 'master' into ci-clippy
taiki-e Jul 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 clippy::all
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()
}
}

#[derive(Debug)]
pub enum LinesCodecError {
MaxLineLengthExceeded,
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
3 changes: 2 additions & 1 deletion tokio-reactor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![deny(missing_docs, missing_debug_implementations, rust_2018_idioms)]
#![cfg_attr(test, deny(warnings))]
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
#![allow(clippy::trivially_copy_pass_by_ref)]
taiki-e marked this conversation as resolved.
Show resolved Hide resolved

//! Event loop that drives Tokio I/O resources.
//!
Expand Down Expand Up @@ -322,7 +323,7 @@ impl Reactor {
"loop process - {} events, {}.{:03}s",
events,
dur.as_secs(),
dur.subsec_nanos() / 1_000_000
dur.subsec_millis()
);
}

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
1 change: 1 addition & 0 deletions tokio-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#![cfg_attr(test, deny(warnings))]
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
#![feature(async_await)]
#![allow(clippy::trivially_copy_pass_by_ref)]
taiki-e marked this conversation as resolved.
Show resolved Hide resolved

//! Asynchronous synchronization primitives.
//!
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
5 changes: 3 additions & 2 deletions tokio-sync/src/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ impl<T> Sender<T> {
/// ```
/// unimplemented!();
/// ```
#[allow(clippy::needless_lifetimes)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3988
pub async fn closed(&mut self) {
use async_util::future::poll_fn;

Expand Down Expand Up @@ -384,10 +385,10 @@ impl<T> Inner<T> {
None => Ready(Err(RecvError(()))),
}
} else {
return Pending;
Pending
}
} else {
return Pending;
Pending
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions tokio-sync/src/semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,9 @@ impl Permit {
}

match semaphore.poll_permit(Some((cx, self)))? {
Ready(v) => {
Ready(()) => {
self.state = PermitState::Acquired;
Ready(Ok(v))
Ready(Ok(()))
}
Pending => {
self.state = PermitState::Waiting;
Expand Down Expand Up @@ -671,6 +671,12 @@ impl Permit {
}
}

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

// ===== impl AcquireError ====

impl AcquireError {
Expand Down Expand Up @@ -874,6 +880,7 @@ impl WaiterNode {
NodeState::store(&self.state, Idle, Relaxed);
}

#[allow(clippy::wrong_self_convention)]
carllerche marked this conversation as resolved.
Show resolved Hide resolved
fn into_non_null(arc: Arc<WaiterNode>) -> NonNull<WaiterNode> {
let ptr = Arc::into_raw(arc);
unsafe { NonNull::new_unchecked(ptr as *mut _) }
Expand Down
4 changes: 3 additions & 1 deletion tokio-sync/src/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ impl<T: Clone> Receiver<T> {
/// Attempts to clone the latest value sent via the channel.
///
/// This is equivalent to calling `Clone` on the value returned by `poll_ref`.
#[allow(clippy::map_clone)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3274
pub fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Option<T>> {
let item = ready!(self.poll_ref(cx));
Ready(item.map(|v_ref| v_ref.clone()))
Expand All @@ -280,6 +281,7 @@ impl<T: Clone> Receiver<T> {
impl<T: Clone> futures_core::Stream for Receiver<T> {
type Item = T;

#[allow(clippy::map_clone)] // false positive: https://github.com/rust-lang/rust-clippy/issues/3274
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<T>> {
let item = ready!(self.poll_ref(cx));
Ready(item.map(|v_ref| v_ref.clone()))
Expand Down Expand Up @@ -376,7 +378,7 @@ impl<T> futures_sink::Sink<T> for Sender<T> {
}

fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error> {
let _ = self.as_ref().get_ref().broadcast(item)?;
self.as_ref().get_ref().broadcast(item)?;
Ok(())
}

Expand Down
Loading