Fix some clippy issues (#704)
This commit is contained in:
parent
3c79f6a2c5
commit
87883876bc
19 changed files with 73 additions and 75 deletions
|
@ -5,8 +5,8 @@ extern crate juniper;
|
|||
use bencher::Bencher;
|
||||
|
||||
use juniper::{
|
||||
execute_sync, tests::model::Database, DefaultScalarValue, EmptyMutation, EmptySubscription,
|
||||
RootNode, Variables,
|
||||
execute_sync, tests::fixtures::starwars::model::Database, DefaultScalarValue, EmptyMutation,
|
||||
EmptySubscription, RootNode, Variables,
|
||||
};
|
||||
|
||||
fn query_type_name(b: &mut Bencher) {
|
||||
|
|
|
@ -595,7 +595,7 @@ where
|
|||
|
||||
/// Add an error to the execution engine at the current executor location
|
||||
pub fn push_error(&self, error: FieldError<S>) {
|
||||
self.push_error_at(error, self.location().clone());
|
||||
self.push_error_at(error, *self.location());
|
||||
}
|
||||
|
||||
/// Add an error to the execution engine at a specific location
|
||||
|
|
|
@ -42,7 +42,7 @@ where
|
|||
{
|
||||
/// Returns the `operation_name` associated with this request.
|
||||
pub fn operation_name(&self) -> Option<&str> {
|
||||
self.operation_name.as_ref().map(|oper_name| &**oper_name)
|
||||
self.operation_name.as_deref()
|
||||
}
|
||||
|
||||
fn variables(&self) -> Variables<S> {
|
||||
|
|
|
@ -42,7 +42,7 @@ where
|
|||
fn from_input_value(v: &InputValue) -> Option<UtcDateTime> {
|
||||
v.as_string_value()
|
||||
.and_then(|s| (s.parse::<DateTime<Utc>>().ok()))
|
||||
.map(|d| UtcDateTime(d))
|
||||
.map(UtcDateTime)
|
||||
}
|
||||
|
||||
fn from_str<'a>(value: ScalarToken<'a>) -> ParseScalarResult<'a, S> {
|
||||
|
|
|
@ -259,7 +259,7 @@ impl GraphQLParserTranslator {
|
|||
.map(|x| GraphQLParserTranslator::translate_argument(&x))
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_else(|| Vec::new());
|
||||
.unwrap_or_else(Vec::new);
|
||||
|
||||
ExternalField {
|
||||
position: Pos::default(),
|
||||
|
|
|
@ -237,7 +237,7 @@ where
|
|||
let sub_exec = executor.field_sub_executor(
|
||||
&response_name,
|
||||
f.name.item,
|
||||
start_pos.clone(),
|
||||
*start_pos,
|
||||
f.selection_set.as_ref().map(|v| &v[..]),
|
||||
);
|
||||
let args = Arguments::new(
|
||||
|
@ -336,7 +336,7 @@ where
|
|||
}));
|
||||
}
|
||||
} else if let Err(e) = sub_result {
|
||||
sub_exec.push_error_at(e, start_pos.clone());
|
||||
sub_exec.push_error_at(e, *start_pos);
|
||||
}
|
||||
} else {
|
||||
async_values.push(AsyncValueFuture::InlineFragment2(async move {
|
||||
|
|
|
@ -457,7 +457,7 @@ where
|
|||
let sub_exec = executor.field_sub_executor(
|
||||
response_name,
|
||||
f.name.item,
|
||||
start_pos.clone(),
|
||||
*start_pos,
|
||||
f.selection_set.as_ref().map(|v| &v[..]),
|
||||
);
|
||||
|
||||
|
@ -482,7 +482,7 @@ where
|
|||
Ok(Value::Null) if meta_field.field_type.is_non_null() => return false,
|
||||
Ok(v) => merge_key_into(result, response_name, v),
|
||||
Err(e) => {
|
||||
sub_exec.push_error_at(e, start_pos.clone());
|
||||
sub_exec.push_error_at(e, *start_pos);
|
||||
|
||||
if meta_field.field_type.is_non_null() {
|
||||
return false;
|
||||
|
@ -540,7 +540,7 @@ where
|
|||
merge_key_into(result, &k, v);
|
||||
}
|
||||
} else if let Err(e) = sub_result {
|
||||
sub_exec.push_error_at(e, start_pos.clone());
|
||||
sub_exec.push_error_at(e, *start_pos);
|
||||
}
|
||||
} else if !resolve_selection_set_into(
|
||||
instance,
|
||||
|
|
|
@ -80,7 +80,7 @@ where
|
|||
T: FromInputValue<S>,
|
||||
S: ScalarValue,
|
||||
{
|
||||
fn from_input_value<'a>(v: &'a InputValue<S>) -> Option<Option<T>> {
|
||||
fn from_input_value(v: &InputValue<S>) -> Option<Option<T>> {
|
||||
match v {
|
||||
&InputValue::Null => Some(None),
|
||||
v => v.convert().map(Some),
|
||||
|
@ -163,7 +163,7 @@ where
|
|||
T: FromInputValue<S>,
|
||||
S: ScalarValue,
|
||||
{
|
||||
fn from_input_value<'a>(v: &'a InputValue<S>) -> Option<Vec<T>>
|
||||
fn from_input_value(v: &InputValue<S>) -> Option<Vec<T>>
|
||||
where {
|
||||
match *v {
|
||||
InputValue::List(ref ls) => {
|
||||
|
|
|
@ -93,7 +93,7 @@ where
|
|||
S: ScalarValue,
|
||||
T: FromInputValue<S>,
|
||||
{
|
||||
fn from_input_value<'a>(v: &'a InputValue<S>) -> Option<Box<T>> {
|
||||
fn from_input_value(v: &InputValue<S>) -> Option<Box<T>> {
|
||||
match <T as FromInputValue<S>>::from_input_value(v) {
|
||||
Some(v) => Some(Box::new(v)),
|
||||
None => None,
|
||||
|
|
|
@ -293,7 +293,7 @@ where
|
|||
let sub_exec = executor.field_sub_executor(
|
||||
response_name,
|
||||
f.name.item,
|
||||
start_pos.clone(),
|
||||
*start_pos,
|
||||
f.selection_set.as_ref().map(|x| &x[..]),
|
||||
);
|
||||
|
||||
|
@ -319,7 +319,7 @@ where
|
|||
}
|
||||
Ok(v) => merge_key_into(&mut object, response_name, v),
|
||||
Err(e) => {
|
||||
sub_exec.push_error_at(e, start_pos.clone());
|
||||
sub_exec.push_error_at(e, *start_pos);
|
||||
|
||||
if meta_field.field_type.is_non_null() {
|
||||
return Value::Null;
|
||||
|
@ -365,7 +365,7 @@ where
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
Err(e) => sub_exec.push_error_at(e, start_pos.clone()),
|
||||
Err(e) => sub_exec.push_error_at(e, *start_pos),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -393,7 +393,7 @@ where
|
|||
merge_key_into(&mut object, &k, v);
|
||||
}
|
||||
} else if let Err(e) = sub_result {
|
||||
sub_exec.push_error_at(e, start_pos.clone());
|
||||
sub_exec.push_error_at(e, *start_pos);
|
||||
}
|
||||
} else if let Some(type_name) = meta_type.name() {
|
||||
let sub_result = instance
|
||||
|
@ -405,7 +405,7 @@ where
|
|||
merge_key_into(&mut object, &k, v);
|
||||
}
|
||||
} else if let Err(e) = sub_result {
|
||||
sub_exec.push_error_at(e, start_pos.clone());
|
||||
sub_exec.push_error_at(e, *start_pos);
|
||||
}
|
||||
} else {
|
||||
return Value::Null;
|
||||
|
|
|
@ -103,10 +103,10 @@ pub fn impl_enum(ast: syn::DeriveInput, error: GraphQLScope) -> syn::Result<Toke
|
|||
if fields.is_empty() {
|
||||
error.not_empty(ast_span);
|
||||
}
|
||||
|
||||
match crate::util::duplicate::Duplicate::find_by_key(&fields, |field| &field.name) {
|
||||
Some(duplicates) => error.duplicate(duplicates.iter()),
|
||||
None => {}
|
||||
if let Some(duplicates) =
|
||||
crate::util::duplicate::Duplicate::find_by_key(&fields, |field| &field.name)
|
||||
{
|
||||
error.duplicate(duplicates.iter())
|
||||
}
|
||||
|
||||
if !attrs.interfaces.is_empty() {
|
||||
|
|
|
@ -102,9 +102,10 @@ pub fn impl_input_object(ast: syn::DeriveInput, error: GraphQLScope) -> syn::Res
|
|||
error.not_empty(ast_span);
|
||||
}
|
||||
|
||||
match crate::util::duplicate::Duplicate::find_by_key(&fields, |field| &field.name) {
|
||||
Some(duplicates) => error.duplicate(duplicates.iter()),
|
||||
None => {}
|
||||
if let Some(duplicates) =
|
||||
crate::util::duplicate::Duplicate::find_by_key(&fields, |field| &field.name)
|
||||
{
|
||||
error.duplicate(duplicates.iter())
|
||||
}
|
||||
|
||||
if !attrs.interfaces.is_empty() {
|
||||
|
|
|
@ -36,13 +36,7 @@ pub fn expand(attr_args: TokenStream, body: TokenStream) -> syn::Result<TokenStr
|
|||
ast.attrs = ast
|
||||
.attrs
|
||||
.into_iter()
|
||||
.filter_map(|attr| {
|
||||
if path_eq_single(&attr.path, "graphql_union") {
|
||||
None
|
||||
} else {
|
||||
Some(attr)
|
||||
}
|
||||
})
|
||||
.filter(|attr| !path_eq_single(&attr.path, "graphql_union"))
|
||||
.collect();
|
||||
|
||||
let meta = UnionMeta::from_attrs("graphql_union", &trait_attrs)?;
|
||||
|
@ -130,13 +124,7 @@ fn parse_variant_from_trait_method(
|
|||
// Remove repeated attributes from the method, to omit incorrect expansion.
|
||||
method.attrs = mem::take(&mut method.attrs)
|
||||
.into_iter()
|
||||
.filter_map(|attr| {
|
||||
if path_eq_single(&attr.path, "graphql_union") {
|
||||
None
|
||||
} else {
|
||||
Some(attr)
|
||||
}
|
||||
})
|
||||
.filter(|attr| !path_eq_single(&attr.path, "graphql_union"))
|
||||
.collect();
|
||||
|
||||
let meta = UnionVariantMeta::from_attrs("graphql_union", &method_attrs)
|
||||
|
@ -299,7 +287,7 @@ fn parse_trait_method_input_args(sig: &syn::Signature) -> Result<Option<syn::Typ
|
|||
return Err(sig.inputs.span());
|
||||
}
|
||||
|
||||
let second_arg_ty = match sig.inputs.iter().skip(1).next() {
|
||||
let second_arg_ty = match sig.inputs.iter().nth(1) {
|
||||
Some(syn::FnArg::Typed(arg)) => arg.ty.deref(),
|
||||
None => return Ok(None),
|
||||
_ => return Err(sig.inputs.span()),
|
||||
|
|
|
@ -696,7 +696,7 @@ fn emerge_union_variants_from_meta(
|
|||
///
|
||||
/// [1]: https://spec.graphql.org/June2018/#sec-Unions
|
||||
/// [2]: https://docs.rs/static_assertions/latest/static_assertions/macro.assert_type_ne_all.html
|
||||
fn all_variants_different(variants: &Vec<UnionVariantDefinition>) -> bool {
|
||||
fn all_variants_different(variants: &[UnionVariantDefinition]) -> bool {
|
||||
let mut types: Vec<_> = variants.iter().map(|var| &var.ty).collect();
|
||||
types.dedup();
|
||||
types.len() == variants.len()
|
||||
|
|
|
@ -14,7 +14,7 @@ pub fn build_object(args: TokenStream, body: TokenStream, error: GraphQLScope) -
|
|||
Ok(definition) => definition,
|
||||
Err(err) => return err.to_compile_error(),
|
||||
};
|
||||
definition.into_tokens().into()
|
||||
definition.into_tokens()
|
||||
}
|
||||
|
||||
/// Generate code for the juniper::graphql_subscription macro.
|
||||
|
@ -27,7 +27,7 @@ pub fn build_subscription(
|
|||
Ok(definition) => definition,
|
||||
Err(err) => return err.to_compile_error(),
|
||||
};
|
||||
definition.into_subscription_tokens().into()
|
||||
definition.into_subscription_tokens()
|
||||
}
|
||||
|
||||
fn create(
|
||||
|
@ -172,9 +172,10 @@ fn create(
|
|||
// Early abort after checking all fields
|
||||
proc_macro_error::abort_if_dirty();
|
||||
|
||||
match crate::util::duplicate::Duplicate::find_by_key(&fields, |field| &field.name) {
|
||||
Some(duplicates) => error.duplicate(duplicates.iter()),
|
||||
None => {}
|
||||
if let Some(duplicates) =
|
||||
crate::util::duplicate::Duplicate::find_by_key(&fields, |field| &field.name)
|
||||
{
|
||||
error.duplicate(duplicates.iter())
|
||||
}
|
||||
|
||||
if !_impl.attrs.is_internal && name.starts_with("__") {
|
||||
|
|
|
@ -183,37 +183,45 @@ pub fn build_scalar(
|
|||
let attrs = syn::parse2::<util::FieldAttributes>(attributes)?;
|
||||
let input = syn::parse2::<ScalarCodegenInput>(body)?;
|
||||
|
||||
let impl_for_type = input.impl_for_type.ok_or(error.custom_error(
|
||||
body_span,
|
||||
"unable to find target for implementation target for `GraphQLScalar`",
|
||||
))?;
|
||||
let impl_for_type = input.impl_for_type.ok_or_else(|| {
|
||||
error.custom_error(
|
||||
body_span,
|
||||
"unable to find target for implementation target for `GraphQLScalar`",
|
||||
)
|
||||
})?;
|
||||
let custom_data_type = input
|
||||
.custom_data_type
|
||||
.ok_or(error.custom_error(body_span, "unable to find custom scalar data type"))?;
|
||||
.ok_or_else(|| error.custom_error(body_span, "unable to find custom scalar data type"))?;
|
||||
let resolve_body = input
|
||||
.resolve_body
|
||||
.ok_or(error.custom_error(body_span, "unable to find body of `resolve` method"))?;
|
||||
let from_input_value_arg = input.from_input_value_arg.ok_or(error.custom_error(
|
||||
body_span,
|
||||
"unable to find argument for `from_input_value` method",
|
||||
))?;
|
||||
let from_input_value_body = input.from_input_value_body.ok_or(error.custom_error(
|
||||
body_span,
|
||||
"unable to find body of `from_input_value` method",
|
||||
))?;
|
||||
let from_input_value_result = input.from_input_value_result.ok_or(error.custom_error(
|
||||
body_span,
|
||||
"unable to find return type of `from_input_value` method",
|
||||
))?;
|
||||
let from_str_arg = input
|
||||
.from_str_arg
|
||||
.ok_or(error.custom_error(body_span, "unable to find argument for `from_str` method"))?;
|
||||
.ok_or_else(|| error.custom_error(body_span, "unable to find body of `resolve` method"))?;
|
||||
let from_input_value_arg = input.from_input_value_arg.ok_or_else(|| {
|
||||
error.custom_error(
|
||||
body_span,
|
||||
"unable to find argument for `from_input_value` method",
|
||||
)
|
||||
})?;
|
||||
let from_input_value_body = input.from_input_value_body.ok_or_else(|| {
|
||||
error.custom_error(
|
||||
body_span,
|
||||
"unable to find body of `from_input_value` method",
|
||||
)
|
||||
})?;
|
||||
let from_input_value_result = input.from_input_value_result.ok_or_else(|| {
|
||||
error.custom_error(
|
||||
body_span,
|
||||
"unable to find return type of `from_input_value` method",
|
||||
)
|
||||
})?;
|
||||
let from_str_arg = input.from_str_arg.ok_or_else(|| {
|
||||
error.custom_error(body_span, "unable to find argument for `from_str` method")
|
||||
})?;
|
||||
let from_str_body = input
|
||||
.from_str_body
|
||||
.ok_or(error.custom_error(body_span, "unable to find body of `from_str` method"))?;
|
||||
let from_str_result = input
|
||||
.from_str_result
|
||||
.ok_or(error.custom_error(body_span, "unable to find return type of `from_str` method"))?;
|
||||
.ok_or_else(|| error.custom_error(body_span, "unable to find body of `from_str` method"))?;
|
||||
let from_str_result = input.from_str_result.ok_or_else(|| {
|
||||
error.custom_error(body_span, "unable to find return type of `from_str` method")
|
||||
})?;
|
||||
|
||||
let name = attrs
|
||||
.name
|
||||
|
|
|
@ -6,7 +6,7 @@ use proc_macro_error::{Diagnostic, Level};
|
|||
use std::fmt;
|
||||
|
||||
/// URL of the GraphQL specification (June 2018 Edition).
|
||||
pub const SPEC_URL: &'static str = "https://spec.graphql.org/June2018/";
|
||||
pub const SPEC_URL: &str = "https://spec.graphql.org/June2018/";
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub enum GraphQLScope {
|
||||
|
|
|
@ -600,7 +600,7 @@ impl FieldAttributes {
|
|||
let doc_comment = get_doc_comment(&attrs);
|
||||
let deprecation = get_deprecated(&attrs);
|
||||
|
||||
let attr_opt = attrs.into_iter().find(|attr| attr.path.is_ident("graphql"));
|
||||
let attr_opt = attrs.iter().find(|attr| attr.path.is_ident("graphql"));
|
||||
|
||||
let mut output = match attr_opt {
|
||||
Some(attr) => attr.parse_args()?,
|
||||
|
|
|
@ -257,7 +257,7 @@ where
|
|||
}
|
||||
_ => {
|
||||
if strict {
|
||||
return Err(format!("Prohibited extra field '{}'", key).to_owned());
|
||||
return Err(format!("Prohibited extra field '{}'", key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue