From 19d1a6bfe52f0ba58915e19560274e78f259c76b Mon Sep 17 00:00:00 2001 From: Jan Michael Auer Date: Fri, 24 Aug 2018 10:29:57 +0200 Subject: [PATCH] build: Enable clippy --- .travis.yml | 13 +++++-------- Makefile | 2 +- src/client.rs | 1 + src/hub.rs | 31 +++++++++++-------------------- 4 files changed, 18 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index abe2d8c9..ae9a2656 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,11 @@ env: # Needed for allow_failures matrix: include: + - env: SUITE=format-check + install: rustup component add rustfmt-preview + - env: SUITE=lint + install: rustup component add clippy-preview + rust: nightly - env: SUITE=check rust: "1.26.0" - env: SUITE=cargotest @@ -26,14 +31,6 @@ matrix: env: SUITE=checkall - os: osx env: SUITE=cargotestall - - env: SUITE=format-check - install: rustup component add rustfmt-preview - - env: SUITE=lint - rust: nightly - install: cargo install --force clippy - allow_failures: - - env: SUITE=lint - rust: nightly notifications: webhooks: diff --git a/Makefile b/Makefile index 0de0e5a9..db8faee6 100644 --- a/Makefile +++ b/Makefile @@ -77,5 +77,5 @@ format-check: .PHONY: format-check lint: - @cargo +nightly clippy --all-features -- -D clippy + @cargo +nightly clippy --all-features --tests -- -D clippy .PHONY: lint diff --git a/src/client.rs b/src/client.rs index 681f1ec0..7593416d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -317,6 +317,7 @@ impl Client { /// If the DSN on the options is set to `None` the client will be entirely /// disabled. pub fn with_options(options: ClientOptions) -> Client { + #[cfg_attr(feature = "cargo-clippy", allow(question_mark))] let transport = if options.dsn.is_none() { None } else { diff --git a/src/hub.rs b/src/hub.rs index 766dc963..d039caab 100644 --- a/src/hub.rs +++ b/src/hub.rs @@ -1,28 +1,23 @@ -#[allow(unused)] +#![allow(unused)] + use std::cell::{Cell, UnsafeCell}; use std::iter; -#[allow(unused)] -use std::sync::{Arc, Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard, TryLockError}; -#[allow(unused)] +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Arc, Mutex, RwLock, TryLockError}; use std::thread; use std::time::Duration; #[cfg(feature = "with_client_implementation")] use fragile::SemiSticky; -#[allow(unused)] -use std::sync::atomic::{AtomicBool, Ordering}; - #[cfg(feature = "with_client_implementation")] use client::Client; use protocol::{Breadcrumb, Event, Level}; use scope::{Scope, ScopeGuard}; - -#[cfg(feature = "with_client_implementation")] -use utils::current_thread; - #[cfg(feature = "with_client_implementation")] use scope::{Stack, StackLayerToken}; +#[cfg(feature = "with_client_implementation")] +use utils::current_thread; use uuid::Uuid; @@ -53,7 +48,7 @@ impl IntoBreadcrumbs for Breadcrumb { type Output = iter::Once; fn into_breadcrumbs(self) -> Self::Output { - return iter::once(self); + iter::once(self) } } @@ -94,6 +89,7 @@ pub(crate) enum PendingProcessor { #[cfg(feature = "with_client_implementation")] impl Box> EventProcessorFactoryFn for F { + #[cfg_attr(feature = "cargo-clippy", allow(boxed_local))] fn call(self: Box) -> Box { let this: Self = *self; this() @@ -254,7 +250,6 @@ impl Hub { /// This is useful for integrations that want to do efficiently nothing if there is no /// client bound. Additionally this internally ensures that the client can be safely /// synchronized. This prevents accidental recursive calls into the client. - #[allow(unused_variables)] pub fn with_active(f: F) -> R where F: FnOnce(&Arc) -> R, @@ -273,6 +268,7 @@ impl Hub { /// Binds a hub to the current thread for the duration of the call. #[cfg(feature = "with_client_implementation")] + #[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))] pub fn run R, R>(hub: Arc, f: F) -> R { hub.flush_pending_processors(); let mut restore_process_hub = false; @@ -305,7 +301,7 @@ impl Hub { // this is for the case where we just switched the hub. This // means we need to catch the panic, restore the // old context and resume the panic if needed. - let rv = panic::catch_unwind(panic::AssertUnwindSafe(|| f())); + let rv = panic::catch_unwind(panic::AssertUnwindSafe(f)); THREAD_HUB.with(|ctx| unsafe { *ctx.get() = old_hub }); if restore_process_hub { USE_PROCESS_HUB.with(|x| x.set(true)); @@ -321,7 +317,6 @@ impl Hub { /// Sends the event to the current client with the current scope. /// /// In case no client is bound this does nothing instead. - #[allow(unused_variables)] pub fn capture_event(&self, event: Event<'static>) -> Uuid { self.flush_pending_processors(); with_client_impl! {{ @@ -337,7 +332,6 @@ impl Hub { } /// Captures an arbitrary message. - #[allow(unused_variables)] pub fn capture_message(&self, msg: &str, level: Level) -> Uuid { self.flush_pending_processors(); with_client_impl! {{ @@ -364,7 +358,6 @@ impl Hub { } /// Drains the currently pending events. - #[allow(unused_variables)] pub fn drain_events(&self, timeout: Option) { with_client_impl! {{ if let Some(ref client) = self.client() { @@ -407,7 +400,6 @@ impl Hub { } /// Invokes a function that can modify the current scope. - #[allow(unused_variables)] pub fn configure_scope(&self, f: F) -> R where R: Default, @@ -428,7 +420,6 @@ impl Hub { /// /// This is equivalent to the global [`sentry::add_breadcrumb`](fn.add_breadcrumb.html) but /// sends the breadcrumb into the hub instead. - #[allow(unused_variables)] pub fn add_breadcrumb(&self, breadcrumb: B) { with_client_impl! {{ self.inner.with_mut(|stack| { @@ -522,7 +513,7 @@ impl Hub { self.inner.has_pending_processors.store(any_left, Ordering::Release); if !new_processors.is_empty() { self.configure_scope(|scope| { - for func in new_processors.into_iter() { + for func in new_processors { scope.event_processors = scope.event_processors.push_back(func); } });