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)+)> {
$(
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| {

View file

@ -100,6 +100,7 @@ impl Droid for DroidData {
}
}
#[derive(Default)]
pub struct Database {
humans: HashMap<String, HumanData>,
droids: HashMap<String, DroidData>,
@ -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()),
}

View file

@ -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() {

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
pub trait ParseScalarValue<S = DefaultScalarValue> {
/// 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

View file

@ -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
}
}

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::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<DeprecationAttr> {
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<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
// 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<Vec<NestedMeta>> {
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<AttributeValue> {
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",

View file

@ -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();

View file

@ -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),

View file

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