diff --git a/juniper/src/macros/interface.rs b/juniper/src/macros/interface.rs index e9b4a8b9..b0c6fa4a 100644 --- a/juniper/src/macros/interface.rs +++ b/juniper/src/macros/interface.rs @@ -190,7 +190,7 @@ macro_rules! graphql_interface { ) -> $crate::ExecutionResult<$crate::__juniper_insert_generic!($($scalar)+)> { $( if field == &$crate::to_camel_case(stringify!($fn_name)) { - let result: $return_ty = (|| { + let f = (|| { $( let $arg_name: $arg_ty = args.get(&$crate::to_camel_case(stringify!($arg_name))) .expect(concat!( @@ -203,7 +203,8 @@ macro_rules! graphql_interface { let $executor = &executor; )* $body - })(); + }); + let result: $return_ty = f(); return $crate::IntoResolvable::into(result, executor.context()) .and_then(|res| { diff --git a/juniper/src/tests/model.rs b/juniper/src/tests/model.rs index 509b8a4d..8731614b 100644 --- a/juniper/src/tests/model.rs +++ b/juniper/src/tests/model.rs @@ -100,6 +100,7 @@ impl Droid for DroidData { } } +#[derive(Default)] pub struct Database { humans: HashMap, droids: HashMap, @@ -122,7 +123,7 @@ impl HumanData { .into_iter() .map(|f| f.to_owned()) .collect(), - appears_in: appears_in.iter().cloned().collect(), + appears_in: appears_in.to_vec(), secret_backstory: secret_backstory.map(|b| b.to_owned()), home_planet: home_planet.map(|p| p.to_owned()), } @@ -146,7 +147,7 @@ impl DroidData { .into_iter() .map(|f| f.to_owned()) .collect(), - appears_in: appears_in.iter().cloned().collect(), + appears_in: appears_in.to_vec(), secret_backstory: secret_backstory.map(|b| b.to_owned()), primary_function: primary_function.map(|p| p.to_owned()), } diff --git a/juniper/src/util.rs b/juniper/src/util.rs index c2b49a84..ccf7a16e 100644 --- a/juniper/src/util.rs +++ b/juniper/src/util.rs @@ -4,7 +4,7 @@ use std::borrow::Cow; /// /// Note: needs to be public because several macros use it. #[doc(hidden)] -pub fn to_camel_case<'a>(s: &'a str) -> Cow<'a, str> { +pub fn to_camel_case<'a>(s: &'a str) -> Cow<'_, str> { let mut dest = Cow::Borrowed(s); for (i, part) in s.split('_').enumerate() { diff --git a/juniper/src/value/scalar.rs b/juniper/src/value/scalar.rs index 60186e45..89b4276d 100644 --- a/juniper/src/value/scalar.rs +++ b/juniper/src/value/scalar.rs @@ -9,7 +9,7 @@ pub type ParseScalarResult<'a, S = DefaultScalarValue> = Result { /// See the trait documentation - fn from_str<'a>(value: ScalarToken<'a>) -> ParseScalarResult<'a, S>; + fn from_str(value: ScalarToken<'_>) -> ParseScalarResult<'_, S>; } /// A trait marking a type that could be used as internal representation of diff --git a/juniper_codegen/src/lib.rs b/juniper_codegen/src/lib.rs index 4c0cc951..79e7cda0 100644 --- a/juniper_codegen/src/lib.rs +++ b/juniper_codegen/src/lib.rs @@ -382,20 +382,18 @@ pub fn graphql_object_internal(args: TokenStream, input: TokenStream) -> TokenSt #[proc_macro_attribute] #[proc_macro_error::proc_macro_error] pub fn graphql_union(attrs: TokenStream, body: TokenStream) -> TokenStream { - let output = match impl_union::impl_union(false, attrs, body) { + match impl_union::impl_union(false, attrs, body) { Ok(toks) => toks, Err(err) => proc_macro_error::abort!(err), - }; - output + } } #[doc(hidden)] #[proc_macro_attribute] #[proc_macro_error::proc_macro_error] pub fn graphql_union_internal(attrs: TokenStream, body: TokenStream) -> TokenStream { - let output = match impl_union::impl_union(true, attrs, body) { + match impl_union::impl_union(true, attrs, body) { Ok(toks) => toks, Err(err) => proc_macro_error::abort!(err), - }; - output + } } diff --git a/juniper_codegen/src/util/mod.rs b/juniper_codegen/src/util/mod.rs index 57d3a7aa..f32aec29 100644 --- a/juniper_codegen/src/util/mod.rs +++ b/juniper_codegen/src/util/mod.rs @@ -20,7 +20,7 @@ pub fn name_of_type(ty: &syn::Type) -> Option { syn::Type::Reference(ref reference) => match &*reference.elem { syn::Type::Path(ref type_path) => Some(&type_path.path), syn::Type::TraitObject(ref trait_obj) => { - match trait_obj.bounds.iter().nth(0).unwrap() { + match trait_obj.bounds.iter().next().unwrap() { syn::TypeParamBound::Trait(ref trait_bound) => Some(&trait_bound.path), _ => None, } @@ -106,25 +106,22 @@ pub fn get_deprecated(attrs: &[Attribute]) -> Option { fn get_deprecated_meta_list(list: &MetaList) -> DeprecationAttr { for meta in &list.nested { - match meta { - &NestedMeta::Meta(Meta::NameValue(ref nv)) => { - if nv.path.is_ident("note") { - match &nv.lit { - &Lit::Str(ref strlit) => { - return DeprecationAttr { - reason: Some(strlit.value()), - }; - } - _ => panic!("deprecated attribute note value only has string literal"), + if let NestedMeta::Meta(Meta::NameValue(ref nv)) = *meta { + if nv.path.is_ident("note") { + match nv.lit { + Lit::Str(ref strlit) => { + return DeprecationAttr { + reason: Some(strlit.value()), + }; } - } else { - panic!( - "Unrecognized setting on #[deprecated(..)] attribute: {:?}", - nv.path, - ); + _ => panic!("deprecated attribute note value only has string literal"), } + } else { + panic!( + "Unrecognized setting on #[deprecated(..)] attribute: {:?}", + nv.path, + ); } - _ => {} } } DeprecationAttr { reason: None } @@ -141,10 +138,10 @@ pub fn get_doc_comment(attrs: &[Attribute]) -> Option { } // Concatenates doc strings into one string. -fn join_doc_strings(docs: &Vec) -> String { +fn join_doc_strings(docs: &[String]) -> String { // Note: this is guaranteed since this function is only called // from get_doc_strings(). - debug_assert!(docs.len() > 0); + debug_assert!(!docs.is_empty()); let last_index = docs.len() - 1; docs.iter() @@ -209,7 +206,7 @@ pub fn get_graphql_attr(attrs: &[Attribute]) -> Option> { for attr in attrs { match attr.parse_meta() { Ok(Meta::List(ref list)) if list.path.is_ident("graphql") => { - return Some(list.nested.iter().map(|x| x.clone()).collect()); + return Some(list.nested.iter().cloned().collect()); } _ => {} } @@ -222,17 +219,17 @@ pub fn keyed_item_value( name: &str, validation: AttributeValidation, ) -> Option { - match item { + match *item { // Attributes in the form of `#[graphql(name = "value")]`. - &NestedMeta::Meta(Meta::NameValue(ref nameval)) if nameval.path.is_ident(name) => { - match &nameval.lit { + NestedMeta::Meta(Meta::NameValue(ref nameval)) if nameval.path.is_ident(name) => { + match nameval.lit { // We have a string attribute value. - &Lit::Str(ref strlit) => Some(AttributeValue::String(strlit.value())), + Lit::Str(ref strlit) => Some(AttributeValue::String(strlit.value())), _ => None, } } // Attributes in the form of `#[graphql(name)]`. - &NestedMeta::Meta(Meta::Path(ref path)) if path.is_ident(name) => match validation { + NestedMeta::Meta(Meta::Path(ref path)) if path.is_ident(name) => match validation { AttributeValidation::String => { panic!(format!( "Invalid format for attribute \"{:?}\": expected a string value", diff --git a/juniper_codegen/src/util/parse_impl.rs b/juniper_codegen/src/util/parse_impl.rs index 8ad40195..85e8e9d7 100644 --- a/juniper_codegen/src/util/parse_impl.rs +++ b/juniper_codegen/src/util/parse_impl.rs @@ -47,10 +47,7 @@ pub struct ImplBlock { impl ImplBlock { /// Check if the block has the special `resolve()` method. pub fn has_resolve_method(&self) -> bool { - self.methods - .iter() - .position(|m| m.sig.ident == "resolve") - .is_some() + self.methods.iter().any(|m| m.sig.ident == "resolve") } /// Parse a 'fn resolve()' method declaration found in union or interface @@ -64,7 +61,7 @@ impl ImplBlock { return Err("Expect a method named 'fn resolve(...)".into()); } - let _type = match &method.sig.output { + match &method.sig.output { syn::ReturnType::Type(_, _) => { return Err("resolve() method must not have a declared return type".into()); } @@ -162,7 +159,7 @@ impl ImplBlock { } }; - let target_trait = match _impl.trait_ { + let target_trait = match _impl.clone().trait_ { Some((_, path, _)) => { let name = path .segments @@ -181,12 +178,12 @@ impl ImplBlock { panic!("Could not determine a name for the impl type"); }; - let target_type = _impl.self_ty; + let target_type = _impl.self_ty.clone(); let description = attrs .description .clone() - .or(util::get_doc_comment(&_impl.attrs)); + .or_else(|| util::get_doc_comment(&_impl.attrs.clone())); let mut methods = Vec::new(); diff --git a/juniper_iron/src/lib.rs b/juniper_iron/src/lib.rs index f733dac6..1479a6ed 100644 --- a/juniper_iron/src/lib.rs +++ b/juniper_iron/src/lib.rs @@ -401,14 +401,6 @@ impl fmt::Display for GraphQLIronError { } impl Error for GraphQLIronError { - fn description(&self) -> &str { - match *self { - GraphQLIronError::Serde(ref err) => err.description(), - GraphQLIronError::Url(ref err) => err.description(), - GraphQLIronError::InvalidData(err) => err, - } - } - fn cause(&self) -> Option<&dyn Error> { match *self { GraphQLIronError::Serde(ref err) => Some(err), diff --git a/juniper_rocket/src/lib.rs b/juniper_rocket/src/lib.rs index ca6c7ecf..fde19fc0 100644 --- a/juniper_rocket/src/lib.rs +++ b/juniper_rocket/src/lib.rs @@ -296,7 +296,7 @@ where } _ => { if strict { - return Err(format!("Prohibited extra field '{}'", key).to_owned()); + return Err(format!("Prohibited extra field '{}'", key)); } } }