More clippy fixes (#565)

This commit is contained in:
Christian Legnitto 2020-03-13 23:02:43 -07:00 committed by GitHub
parent 3b5cf4ad64
commit 2796d8df9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 54 deletions

View file

@ -190,7 +190,7 @@ macro_rules! graphql_interface {
) -> $crate::ExecutionResult<$crate::__juniper_insert_generic!($($scalar)+)> { ) -> $crate::ExecutionResult<$crate::__juniper_insert_generic!($($scalar)+)> {
$( $(
if field == &$crate::to_camel_case(stringify!($fn_name)) { 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))) let $arg_name: $arg_ty = args.get(&$crate::to_camel_case(stringify!($arg_name)))
.expect(concat!( .expect(concat!(
@ -203,7 +203,8 @@ macro_rules! graphql_interface {
let $executor = &executor; let $executor = &executor;
)* )*
$body $body
})(); });
let result: $return_ty = f();
return $crate::IntoResolvable::into(result, executor.context()) return $crate::IntoResolvable::into(result, executor.context())
.and_then(|res| { .and_then(|res| {

View file

@ -100,6 +100,7 @@ impl Droid for DroidData {
} }
} }
#[derive(Default)]
pub struct Database { pub struct Database {
humans: HashMap<String, HumanData>, humans: HashMap<String, HumanData>,
droids: HashMap<String, DroidData>, droids: HashMap<String, DroidData>,
@ -122,7 +123,7 @@ impl HumanData {
.into_iter() .into_iter()
.map(|f| f.to_owned()) .map(|f| f.to_owned())
.collect(), .collect(),
appears_in: appears_in.iter().cloned().collect(), appears_in: appears_in.to_vec(),
secret_backstory: secret_backstory.map(|b| b.to_owned()), secret_backstory: secret_backstory.map(|b| b.to_owned()),
home_planet: home_planet.map(|p| p.to_owned()), home_planet: home_planet.map(|p| p.to_owned()),
} }
@ -146,7 +147,7 @@ impl DroidData {
.into_iter() .into_iter()
.map(|f| f.to_owned()) .map(|f| f.to_owned())
.collect(), .collect(),
appears_in: appears_in.iter().cloned().collect(), appears_in: appears_in.to_vec(),
secret_backstory: secret_backstory.map(|b| b.to_owned()), secret_backstory: secret_backstory.map(|b| b.to_owned()),
primary_function: primary_function.map(|p| p.to_owned()), primary_function: primary_function.map(|p| p.to_owned()),
} }

View file

@ -4,7 +4,7 @@ use std::borrow::Cow;
/// ///
/// Note: needs to be public because several macros use it. /// Note: needs to be public because several macros use it.
#[doc(hidden)] #[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); let mut dest = Cow::Borrowed(s);
for (i, part) in s.split('_').enumerate() { for (i, part) in s.split('_').enumerate() {

View file

@ -9,7 +9,7 @@ pub type ParseScalarResult<'a, S = DefaultScalarValue> = Result<S, ParseError<'a
/// A trait used to convert a `ScalarToken` into a certain scalar value type /// A trait used to convert a `ScalarToken` into a certain scalar value type
pub trait ParseScalarValue<S = DefaultScalarValue> { pub trait ParseScalarValue<S = DefaultScalarValue> {
/// See the trait documentation /// 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 /// A trait marking a type that could be used as internal representation of

View file

@ -382,20 +382,18 @@ pub fn graphql_object_internal(args: TokenStream, input: TokenStream) -> TokenSt
#[proc_macro_attribute] #[proc_macro_attribute]
#[proc_macro_error::proc_macro_error] #[proc_macro_error::proc_macro_error]
pub fn graphql_union(attrs: TokenStream, body: TokenStream) -> TokenStream { 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, Ok(toks) => toks,
Err(err) => proc_macro_error::abort!(err), Err(err) => proc_macro_error::abort!(err),
}; }
output
} }
#[doc(hidden)] #[doc(hidden)]
#[proc_macro_attribute] #[proc_macro_attribute]
#[proc_macro_error::proc_macro_error] #[proc_macro_error::proc_macro_error]
pub fn graphql_union_internal(attrs: TokenStream, body: TokenStream) -> TokenStream { 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, Ok(toks) => toks,
Err(err) => proc_macro_error::abort!(err), Err(err) => proc_macro_error::abort!(err),
}; }
output
} }

View file

@ -20,7 +20,7 @@ pub fn name_of_type(ty: &syn::Type) -> Option<syn::Ident> {
syn::Type::Reference(ref reference) => match &*reference.elem { syn::Type::Reference(ref reference) => match &*reference.elem {
syn::Type::Path(ref type_path) => Some(&type_path.path), syn::Type::Path(ref type_path) => Some(&type_path.path),
syn::Type::TraitObject(ref trait_obj) => { 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), syn::TypeParamBound::Trait(ref trait_bound) => Some(&trait_bound.path),
_ => None, _ => None,
} }
@ -106,25 +106,22 @@ pub fn get_deprecated(attrs: &[Attribute]) -> Option<DeprecationAttr> {
fn get_deprecated_meta_list(list: &MetaList) -> DeprecationAttr { fn get_deprecated_meta_list(list: &MetaList) -> DeprecationAttr {
for meta in &list.nested { for meta in &list.nested {
match meta { if let NestedMeta::Meta(Meta::NameValue(ref nv)) = *meta {
&NestedMeta::Meta(Meta::NameValue(ref nv)) => { if nv.path.is_ident("note") {
if nv.path.is_ident("note") { match nv.lit {
match &nv.lit { Lit::Str(ref strlit) => {
&Lit::Str(ref strlit) => { return DeprecationAttr {
return DeprecationAttr { reason: Some(strlit.value()),
reason: Some(strlit.value()), };
};
}
_ => panic!("deprecated attribute note value only has string literal"),
} }
} else { _ => panic!("deprecated attribute note value only has string literal"),
panic!(
"Unrecognized setting on #[deprecated(..)] attribute: {:?}",
nv.path,
);
} }
} else {
panic!(
"Unrecognized setting on #[deprecated(..)] attribute: {:?}",
nv.path,
);
} }
_ => {}
} }
} }
DeprecationAttr { reason: None } DeprecationAttr { reason: None }
@ -141,10 +138,10 @@ pub fn get_doc_comment(attrs: &[Attribute]) -> Option<String> {
} }
// Concatenates doc strings into one string. // Concatenates doc strings into one string.
fn join_doc_strings(docs: &Vec<String>) -> String { fn join_doc_strings(docs: &[String]) -> String {
// Note: this is guaranteed since this function is only called // Note: this is guaranteed since this function is only called
// from get_doc_strings(). // from get_doc_strings().
debug_assert!(docs.len() > 0); debug_assert!(!docs.is_empty());
let last_index = docs.len() - 1; let last_index = docs.len() - 1;
docs.iter() docs.iter()
@ -209,7 +206,7 @@ pub fn get_graphql_attr(attrs: &[Attribute]) -> Option<Vec<NestedMeta>> {
for attr in attrs { for attr in attrs {
match attr.parse_meta() { match attr.parse_meta() {
Ok(Meta::List(ref list)) if list.path.is_ident("graphql") => { 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, name: &str,
validation: AttributeValidation, validation: AttributeValidation,
) -> Option<AttributeValue> { ) -> Option<AttributeValue> {
match item { match *item {
// Attributes in the form of `#[graphql(name = "value")]`. // Attributes in the form of `#[graphql(name = "value")]`.
&NestedMeta::Meta(Meta::NameValue(ref nameval)) if nameval.path.is_ident(name) => { NestedMeta::Meta(Meta::NameValue(ref nameval)) if nameval.path.is_ident(name) => {
match &nameval.lit { match nameval.lit {
// We have a string attribute value. // 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, _ => None,
} }
} }
// Attributes in the form of `#[graphql(name)]`. // 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 => { AttributeValidation::String => {
panic!(format!( panic!(format!(
"Invalid format for attribute \"{:?}\": expected a string value", "Invalid format for attribute \"{:?}\": expected a string value",

View file

@ -47,10 +47,7 @@ pub struct ImplBlock {
impl ImplBlock { impl ImplBlock {
/// Check if the block has the special `resolve()` method. /// Check if the block has the special `resolve()` method.
pub fn has_resolve_method(&self) -> bool { pub fn has_resolve_method(&self) -> bool {
self.methods self.methods.iter().any(|m| m.sig.ident == "resolve")
.iter()
.position(|m| m.sig.ident == "resolve")
.is_some()
} }
/// Parse a 'fn resolve()' method declaration found in union or interface /// 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()); return Err("Expect a method named 'fn resolve(...)".into());
} }
let _type = match &method.sig.output { match &method.sig.output {
syn::ReturnType::Type(_, _) => { syn::ReturnType::Type(_, _) => {
return Err("resolve() method must not have a declared return type".into()); 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, _)) => { Some((_, path, _)) => {
let name = path let name = path
.segments .segments
@ -181,12 +178,12 @@ impl ImplBlock {
panic!("Could not determine a name for the impl type"); 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 let description = attrs
.description .description
.clone() .clone()
.or(util::get_doc_comment(&_impl.attrs)); .or_else(|| util::get_doc_comment(&_impl.attrs.clone()));
let mut methods = Vec::new(); let mut methods = Vec::new();

View file

@ -401,14 +401,6 @@ impl fmt::Display for GraphQLIronError {
} }
impl Error 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> { fn cause(&self) -> Option<&dyn Error> {
match *self { match *self {
GraphQLIronError::Serde(ref err) => Some(err), GraphQLIronError::Serde(ref err) => Some(err),

View file

@ -296,7 +296,7 @@ where
} }
_ => { _ => {
if strict { if strict {
return Err(format!("Prohibited extra field '{}'", key).to_owned()); return Err(format!("Prohibited extra field '{}'", key));
} }
} }
} }