From d08d9bea8c6c0a1f22030c9d4b58a76c61362f58 Mon Sep 17 00:00:00 2001 From: Dominic Date: Sat, 25 Apr 2020 17:01:16 +0200 Subject: [PATCH] fix some clippy warnings --- gotham_restful/src/auth.rs | 4 +- gotham_restful/src/lib.rs | 1 + gotham_restful/src/openapi/router.rs | 4 +- gotham_restful/src/openapi/types.rs | 7 +++- gotham_restful_derive/src/method.rs | 45 +++++++++++------------ gotham_restful_derive/src/openapi_type.rs | 31 +++++++--------- gotham_restful_derive/src/request_body.rs | 2 +- 7 files changed, 46 insertions(+), 48 deletions(-) diff --git a/gotham_restful/src/auth.rs b/gotham_restful/src/auth.rs index 8324622..94c95fd 100644 --- a/gotham_restful/src/auth.rs +++ b/gotham_restful/src/auth.rs @@ -240,7 +240,7 @@ where // get the secret from the handler, possibly decoding claims ourselves let secret = self.handler.jwt_secret(state, || { - let b64 = token.split(".").nth(1)?; + let b64 = token.split('.').nth(1)?; let raw = base64::decode_config(b64, base64::URL_SAFE_NO_PAD).ok()?; serde_json::from_slice(&raw).ok()? }); @@ -261,7 +261,7 @@ where }; // we found a valid token - return AuthStatus::Authenticated(data); + AuthStatus::Authenticated(data) } } diff --git a/gotham_restful/src/lib.rs b/gotham_restful/src/lib.rs index 9bc4674..a31247c 100644 --- a/gotham_restful/src/lib.rs +++ b/gotham_restful/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::tabs_in_doc_comments)] /*! This crate is an extension to the popular [gotham web framework][gotham] for Rust. The idea is to have several RESTful resources that can be added to the gotham router. This crate will take care diff --git a/gotham_restful/src/openapi/router.rs b/gotham_restful/src/openapi/router.rs index a5ea5eb..d69c111 100644 --- a/gotham_restful/src/openapi/router.rs +++ b/gotham_restful/src/openapi/router.rs @@ -136,7 +136,7 @@ impl NewHandler for OpenapiHandler } #[cfg(feature = "auth")] -const SECURITY_NAME : &'static str = "authToken"; +const SECURITY_NAME : &str = "authToken"; #[cfg(feature = "auth")] fn get_security(state : &mut State) -> IndexMap> @@ -249,7 +249,7 @@ impl<'a> OperationParams<'a> { params.push(Item(Parameter::Path { parameter_data: ParameterData { - name: param.to_string(), + name: (*param).to_string(), description: None, required: true, deprecated: None, diff --git a/gotham_restful/src/openapi/types.rs b/gotham_restful/src/openapi/types.rs index 5cbacce..49e5e57 100644 --- a/gotham_restful/src/openapi/types.rs +++ b/gotham_restful/src/openapi/types.rs @@ -9,7 +9,10 @@ use openapiv3::{ }; #[cfg(feature = "uuid")] use uuid::Uuid; -use std::collections::{BTreeSet, HashSet}; +use std::{ + collections::{BTreeSet, HashSet}, + hash::BuildHasher +}; /** This struct needs to be available for every type that can be part of an OpenAPI Spec. It is @@ -296,7 +299,7 @@ impl OpenapiType for BTreeSet } } -impl OpenapiType for HashSet +impl OpenapiType for HashSet { fn schema() -> OpenapiSchema { diff --git a/gotham_restful_derive/src/method.rs b/gotham_restful_derive/src/method.rs index d83f6ab..514bb4a 100644 --- a/gotham_restful_derive/src/method.rs +++ b/gotham_restful_derive/src/method.rs @@ -120,6 +120,7 @@ impl Method } } +#[allow(clippy::large_enum_variant)] enum MethodArgumentType { StateRef, @@ -176,9 +177,8 @@ impl Spanned for MethodArgument fn interpret_arg_ty(index : usize, attrs : &[Attribute], name : &str, ty : Type) -> Result { - let attr = attrs.into_iter() - .filter(|arg| arg.path.segments.iter().filter(|path| &path.ident.to_string() == "rest_arg").nth(0).is_some()) - .nth(0) + let attr = attrs.iter() + .find(|arg| arg.path.segments.iter().any(|path| &path.ident.to_string() == "rest_arg")) .map(|arg| arg.tokens.to_string()); if cfg!(feature = "auth") && (attr.as_deref() == Some("auth") || (attr.is_none() && name == "auth")) @@ -219,19 +219,17 @@ fn interpret_arg(index : usize, arg : &PatType) -> Result } #[cfg(feature = "openapi")] -fn expand_operation_id(attrs : &AttributeArgs) -> TokenStream2 +fn expand_operation_id(attrs : &[NestedMeta]) -> TokenStream2 { let mut operation_id : Option<&Lit> = None; for meta in attrs { - match meta { - NestedMeta::Meta(Meta::NameValue(kv)) => { - if kv.path.segments.last().map(|p| p.ident.to_string()) == Some("operation_id".to_owned()) - { - operation_id = Some(&kv.lit) - } - }, - _ => {} + if let NestedMeta::Meta(Meta::NameValue(kv)) = meta + { + if kv.path.segments.last().map(|p| p.ident.to_string()) == Some("operation_id".to_owned()) + { + operation_id = Some(&kv.lit) + } } } @@ -247,25 +245,23 @@ fn expand_operation_id(attrs : &AttributeArgs) -> TokenStream2 } #[cfg(not(feature = "openapi"))] -fn expand_operation_id(_ : &AttributeArgs) -> TokenStream2 +fn expand_operation_id(_ : &[NestedMeta]) -> TokenStream2 { quote!() } -fn expand_wants_auth(attrs : &AttributeArgs, default : bool) -> TokenStream2 +fn expand_wants_auth(attrs : &[NestedMeta], default : bool) -> TokenStream2 { let default_lit = Lit::Bool(LitBool { value: default, span: Span::call_site() }); let mut wants_auth = &default_lit; for meta in attrs { - match meta { - NestedMeta::Meta(Meta::NameValue(kv)) => { - if kv.path.segments.last().map(|p| p.ident.to_string()) == Some("wants_auth".to_owned()) - { - wants_auth = &kv.lit - } - }, - _ => {} + if let NestedMeta::Meta(Meta::NameValue(kv)) = meta + { + if kv.path.segments.last().map(|p| p.ident.to_string()) == Some("wants_auth".to_owned()) + { + wants_auth = &kv.lit + } } } @@ -277,6 +273,7 @@ fn expand_wants_auth(attrs : &AttributeArgs, default : bool) -> TokenStream2 } } +#[allow(clippy::comparison_chain)] fn expand(method : Method, attrs : TokenStream, item : TokenStream) -> Result { let krate = super::krate(); @@ -381,7 +378,7 @@ fn expand(method : Method, attrs : TokenStream, item : TokenStream) -> Result Result TokenStream2 { if generics.params.is_empty() { - quote!() + return quote!(); } - else - { - let krate = super::krate(); - let idents = generics.params.iter() - .map(|param| match param { - GenericParam::Type(ty) => Some(ty.ident.clone()), - _ => None - }) - .filter(|param| param.is_some()) - .map(|param| param.unwrap()); - - quote! { - where #(#idents : #krate::OpenapiType),* - } + + let krate = super::krate(); + let idents = generics.params.iter() + .map(|param| match param { + GenericParam::Type(ty) => Some(ty.ident.clone()), + _ => None + }) + .filter(|param| param.is_some()) + .map(|param| param.unwrap()); + + quote! { + where #(#idents : #krate::OpenapiType),* } } @@ -98,8 +96,7 @@ fn remove_parens(input : TokenStream2) -> TokenStream2 } Box::new(iter::once(tt)) }); - let output = TokenStream2::from_iter(iter); - output + TokenStream2::from_iter(iter) } fn parse_attributes(input : &[Attribute]) -> Result diff --git a/gotham_restful_derive/src/request_body.rs b/gotham_restful_derive/src/request_body.rs index 6c6f473..7bc5d9d 100644 --- a/gotham_restful_derive/src/request_body.rs +++ b/gotham_restful_derive/src/request_body.rs @@ -67,7 +67,7 @@ fn expand(tokens : TokenStream) -> Result .filter(|attr| attr.path.segments.iter().last().map(|segment| segment.ident.to_string()) == Some("supported_types".to_string())) .flat_map(|attr| syn::parse2::(attr.tokens) - .map(|list| Box::new(list.0.into_iter().map(|mime| Ok(mime))) as Box>>) + .map(|list| Box::new(list.0.into_iter().map(Ok)) as Box>>) .unwrap_or_else(|err| Box::new(iter::once(Err(err))))) .collect_to_result()?;