From 5d7634c9753c12a5ecc6ca8f8b01d601f72ab51d Mon Sep 17 00:00:00 2001 From: Mrmaxmeier Date: Sat, 25 Feb 2017 14:12:04 +0100 Subject: [PATCH] Fix a bunch of clippy warnings --- src/ast.rs | 12 ++--- src/executor.rs | 14 +++-- src/integrations/iron_handlers.rs | 2 +- src/macros/enums.rs | 8 +-- src/macros/field.rs | 2 +- src/macros/interface.rs | 4 +- src/parser/lexer.rs | 2 +- src/parser/value.rs | 2 +- src/schema/meta.rs | 30 +++++------ src/schema/model.rs | 16 +++--- src/schema/schema.rs | 4 +- src/types/base.rs | 40 ++++++-------- src/types/utilities.rs | 16 +++--- src/validation/context.rs | 4 +- src/validation/input_value.rs | 36 ++++++------- src/validation/multi_visitor.rs | 2 +- .../rules/arguments_of_correct_type.rs | 10 ++-- .../rules/default_values_of_correct_type.rs | 6 +-- .../rules/fields_on_correct_type.rs | 6 +-- .../rules/fragments_on_composite_types.rs | 10 ++-- src/validation/rules/known_argument_names.rs | 20 +++---- src/validation/rules/known_directives.rs | 2 +- src/validation/rules/known_fragment_names.rs | 4 +- src/validation/rules/known_type_names.rs | 6 +-- src/validation/rules/no_fragment_cycles.rs | 14 ++--- .../rules/no_undefined_variables.rs | 16 +++--- src/validation/rules/no_unused_fragments.rs | 14 ++--- src/validation/rules/no_unused_variables.rs | 16 +++--- .../rules/overlapping_fields_can_be_merged.rs | 53 +++++++++---------- .../rules/possible_fragment_spreads.rs | 12 ++--- src/validation/rules/unique_argument_names.rs | 4 +- src/validation/rules/unique_fragment_names.rs | 4 +- .../rules/unique_operation_names.rs | 6 +-- src/validation/rules/unique_variable_names.rs | 4 +- .../rules/variables_are_input_types.rs | 2 +- .../rules/variables_in_allowed_position.rs | 21 ++++---- src/validation/visitor.rs | 12 ++--- 37 files changed, 213 insertions(+), 223 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 64ee69ad..98960358 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -168,7 +168,7 @@ impl<'a> Type<'a> { /// Only applies to named types; lists will return `None`. pub fn name(&self) -> Option<&str> { match *self { - Type::Named(ref n) | Type::NonNullNamed(ref n) => Some(n), + Type::Named(n) | Type::NonNullNamed(n) => Some(n), _ => None } } @@ -178,7 +178,7 @@ impl<'a> Type<'a> { /// All type literals contain exactly one named type. pub fn innermost_name(&self) -> &str { match *self { - Type::Named(ref n) | Type::NonNullNamed(ref n) => n, + Type::Named(n) | Type::NonNullNamed(n) => n, Type::List(ref l) | Type::NonNullList(ref l) => l.innermost_name(), } } @@ -195,8 +195,8 @@ impl<'a> Type<'a> { impl<'a> fmt::Display for Type<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - Type::Named(ref n) => write!(f, "{}", n), - Type::NonNullNamed(ref n) => write!(f, "{}!", n), + Type::Named(n) => write!(f, "{}", n), + Type::NonNullNamed(n) => write!(f, "{}!", n), Type::List(ref t) => write!(f, "[{}]", t), Type::NonNullList(ref t) => write!(f, "[{}]!", t), } @@ -237,7 +237,7 @@ impl InputValue { /// not contain any location information. Can be used from `ToInputValue` /// implementations, where no source code position information is available. pub fn list(l: Vec) -> InputValue { - InputValue::List(l.into_iter().map(|i| Spanning::unlocated(i)).collect()) + InputValue::List(l.into_iter().map(Spanning::unlocated).collect()) } /// Construct a located list. @@ -371,7 +371,7 @@ impl InputValue { (&Variable(ref s1), &Variable(ref s2)) => s1 == s2, (&Boolean(b1), &Boolean(b2)) => b1 == b2, (&List(ref l1), &List(ref l2)) => - l1.iter().zip(l2.iter()).all(|(ref v1, ref v2)| v1.item.unlocated_eq(&v2.item)), + l1.iter().zip(l2.iter()).all(|(v1, v2)| v1.item.unlocated_eq(&v2.item)), (&Object(ref o1), &Object(ref o2)) => o1.len() == o2.len() && o1.iter() diff --git a/src/executor.rs b/src/executor.rs index 9715f704..dcde70e2 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -96,7 +96,7 @@ impl<'a, T: GraphQLType, C> IntoResolvable<'a, T, C> for Option<(&'a T::Context, impl<'a, T: GraphQLType, C> IntoResolvable<'a, T, C> for FieldResult<(&'a T::Context, T)> { fn into(self, _: &'a C) -> FieldResult> { - self.map(|v| Some(v)) + self.map(Some) } } @@ -148,7 +148,7 @@ impl<'a, CtxT> Executor<'a, CtxT> { ) -> ExecutionResult where NewCtxT: FromContext, { - self.replaced_context(>::from(&self.context)) + self.replaced_context(>::from(self.context)) .resolve(value) } @@ -179,7 +179,7 @@ impl<'a, CtxT> Executor<'a, CtxT> { Executor { fragments: self.fragments, variables: self.variables, - current_selection_set: self.current_selection_set.clone(), + current_selection_set: self.current_selection_set, schema: self.schema, context: ctx, errors: self.errors, @@ -252,9 +252,9 @@ impl<'a> FieldPath<'a> { fn construct_path(&self, acc: &mut Vec) { match *self { FieldPath::Root(_) => (), - FieldPath::Field(ref name, _, ref parent) => { + FieldPath::Field(name, _, parent) => { parent.construct_path(acc); - acc.push((*name).to_owned()); + acc.push(name.to_owned()); } } } @@ -347,9 +347,7 @@ pub fn execute_validated_query<'a, QueryT, MutationT, CtxT>( all_vars = variables.clone(); for (name, value) in defaults { - if !all_vars.contains_key(&name) { - all_vars.insert(name, value); - } + all_vars.entry(name).or_insert(value); } final_vars = &all_vars; diff --git a/src/integrations/iron_handlers.rs b/src/integrations/iron_handlers.rs index c5657e8d..194f000e 100644 --- a/src/integrations/iron_handlers.rs +++ b/src/integrations/iron_handlers.rs @@ -86,7 +86,7 @@ impl<'a, CtxFactory, Query, Mutation, CtxT> let mut query = None; let mut variables = Variables::new(); - for (k, v) in json_obj.into_iter() { + for (k, v) in json_obj { if k == "query" { query = v.as_string().map(|s| s.to_owned()); } diff --git a/src/macros/enums.rs b/src/macros/enums.rs index be143d23..1c27b469 100644 --- a/src/macros/enums.rs +++ b/src/macros/enums.rs @@ -84,9 +84,9 @@ macro_rules! graphql_enum { } fn resolve(&self, _: Option<&[$crate::Selection]>, _: &$crate::Executor) -> $crate::Value { - match self { + match *self { $( - &graphql_enum!(@as_pattern, $eval) => + graphql_enum!(@as_pattern, $eval) => $crate::Value::string(graphql_enum!(@as_expr, $ename)) ),* } } @@ -105,9 +105,9 @@ macro_rules! graphql_enum { impl $crate::ToInputValue for $name { fn to(&self) -> $crate::InputValue { - match self { + match *self { $( - &graphql_enum!(@as_pattern, $eval) => + graphql_enum!(@as_pattern, $eval) => $crate::InputValue::string(graphql_enum!(@as_expr, $ename)) ),* } } diff --git a/src/macros/field.rs b/src/macros/field.rs index eadd7069..79b8ebc9 100644 --- a/src/macros/field.rs +++ b/src/macros/field.rs @@ -69,7 +69,7 @@ macro_rules! __graphql__build_field_matches { ) => { $( if $fieldvar == &$crate::to_camel_case(stringify!($name)) { - let result: $t = (|| { + let result: $t = (||{ __graphql__args!( @assign_arg_vars, $argsvar, $executorvar, $($args)* diff --git a/src/macros/interface.rs b/src/macros/interface.rs index b0e55a82..b52f5d5e 100644 --- a/src/macros/interface.rs +++ b/src/macros/interface.rs @@ -191,7 +191,7 @@ macro_rules! graphql_interface { let $ctxtvar = &$ctxtarg; $( - if let Some(_) = $resolver as Option<$srctype> { + if ($resolver as Option<$srctype>).is_some() { return (<$srctype as $crate::GraphQLType>::name()).unwrap().to_owned(); } )* @@ -208,7 +208,7 @@ macro_rules! graphql_interface { let $ctxtvar = &$execarg.context(); $( - if $typenamearg == (<$srctype as $crate::GraphQLType>::name()).unwrap().to_owned() { + if $typenamearg == (<$srctype as $crate::GraphQLType>::name()).unwrap() { return $execarg.resolve(&$resolver); } )* diff --git a/src/parser/lexer.rs b/src/parser/lexer.rs index 2dbe4ec5..97bfca6d 100644 --- a/src/parser/lexer.rs +++ b/src/parser/lexer.rs @@ -469,7 +469,7 @@ impl<'a> Iterator for Lexer<'a> { impl<'a> fmt::Display for Token<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - Token::Name(ref name) => write!(f, "{}", name), + Token::Name(name) => write!(f, "{}", name), Token::Int(i) => write!(f, "{}", i), Token::Float(v) => write!(f, "{}", v), Token::String(ref s) => write!(f, "\"{}\"", s.replace('\\', "\\\\").replace('"', "\\\"")), diff --git a/src/parser/value.rs b/src/parser/value.rs index cda1607d..1c090317 100644 --- a/src/parser/value.rs +++ b/src/parser/value.rs @@ -36,7 +36,7 @@ fn parse_list_literal<'a>(parser: &mut Parser<'a>, is_const: bool) -> ParseResul &Token::BracketOpen, |p| parse_value_literal(p, is_const), &Token::BracketClose - )).map(|items| InputValue::parsed_list(items))) + )).map(InputValue::parsed_list)) } fn parse_object_literal<'a>(parser: &mut Parser<'a>, is_const: bool) -> ParseResult<'a, InputValue> { diff --git a/src/schema/meta.rs b/src/schema/meta.rs index 067d3b23..017ce1bc 100644 --- a/src/schema/meta.rs +++ b/src/schema/meta.rs @@ -174,12 +174,12 @@ impl<'a> MetaType<'a> { /// Lists, non-null wrappers, and placeholders don't have names. pub fn name(&self) -> Option<&str> { match *self { - MetaType::Scalar(ScalarMeta { ref name, .. }) | - MetaType::Object(ObjectMeta { ref name, .. }) | - MetaType::Enum(EnumMeta { ref name, .. }) | - MetaType::Interface(InterfaceMeta { ref name, .. }) | - MetaType::Union(UnionMeta { ref name, .. }) | - MetaType::InputObject(InputObjectMeta { ref name, .. }) => + MetaType::Scalar(ScalarMeta { name, .. }) | + MetaType::Object(ObjectMeta { name, .. }) | + MetaType::Enum(EnumMeta { name, .. }) | + MetaType::Interface(InterfaceMeta { name, .. }) | + MetaType::Union(UnionMeta { name, .. }) | + MetaType::InputObject(InputObjectMeta { name, .. }) => Some(name), _ => None, } @@ -226,7 +226,7 @@ impl<'a> MetaType<'a> { match *self { MetaType::Object(ObjectMeta { ref fields, .. }) | MetaType::Interface(InterfaceMeta { ref fields, .. }) => - fields.iter().filter(|f| f.name == name).next(), + fields.iter().find(|f| f.name == name), _ => None, } } @@ -237,7 +237,7 @@ impl<'a> MetaType<'a> { pub fn input_field_by_name(&self, name: &str) -> Option<&Argument> { match *self { MetaType::InputObject(InputObjectMeta { ref input_fields, .. }) => - input_fields.iter().filter(|f| f.name == name).next(), + input_fields.iter().find(|f| f.name == name), _ => None, } } @@ -245,18 +245,18 @@ impl<'a> MetaType<'a> { /// Construct a `Type` literal instance based on the metadata pub fn as_type(&self) -> Type<'a> { match *self { - MetaType::Scalar(ScalarMeta { ref name, .. }) | - MetaType::Object(ObjectMeta { ref name, .. }) | - MetaType::Enum(EnumMeta { ref name, .. }) | - MetaType::Interface(InterfaceMeta { ref name, .. }) | - MetaType::Union(UnionMeta { ref name, .. }) | - MetaType::InputObject(InputObjectMeta { ref name, .. }) => + MetaType::Scalar(ScalarMeta { name, .. }) | + MetaType::Object(ObjectMeta { name, .. }) | + MetaType::Enum(EnumMeta { name, .. }) | + MetaType::Interface(InterfaceMeta { name, .. }) | + MetaType::Union(UnionMeta { name, .. }) | + MetaType::InputObject(InputObjectMeta { name, .. }) => Type::NonNullNamed(name), MetaType::List(ListMeta { ref of_type }) => Type::NonNullList(Box::new(of_type.clone())), MetaType::Nullable(NullableMeta { ref of_type }) => match *of_type { - Type::NonNullNamed(ref inner) => Type::Named(inner.to_owned()), + Type::NonNullNamed(inner) => Type::Named(inner), Type::NonNullList(ref inner) => Type::List(inner.clone()), ref t => t.clone(), }, diff --git a/src/schema/model.rs b/src/schema/model.rs index a33c9faf..2337a2a8 100644 --- a/src/schema/model.rs +++ b/src/schema/model.rs @@ -97,7 +97,7 @@ impl<'a> SchemaType<'a> { ]; if let Some(root_type) = registry.types.get_mut(&query_type_name) { - if let &mut MetaType::Object(ObjectMeta { ref mut fields, .. }) = root_type { + if let MetaType::Object(ObjectMeta { ref mut fields, .. }) = *root_type { fields.append(&mut meta_fields); } else { @@ -171,13 +171,13 @@ impl<'a> SchemaType<'a> { pub fn make_type(&self, t: &Type) -> TypeType { match *t { - Type::NonNullNamed(ref n) => + Type::NonNullNamed(n) => TypeType::NonNull(Box::new( self.type_by_name(n).expect("Type not found in schema"))), Type::NonNullList(ref inner) => TypeType::NonNull(Box::new( TypeType::List(Box::new(self.make_type(inner))))), - Type::Named(ref n) => self.type_by_name(n).expect("Type not found in schema"), + Type::Named(n) => self.type_by_name(n).expect("Type not found in schema"), Type::List(ref inner) => TypeType::List(Box::new(self.make_type(inner))), } @@ -211,7 +211,7 @@ impl<'a> SchemaType<'a> { .iter() .flat_map(|t| self.concrete_type_by_name(t)) .collect(), - MetaType::Interface(InterfaceMeta { ref name, .. }) => + MetaType::Interface(InterfaceMeta { name, .. }) => self.concrete_type_list() .into_iter() .filter(|t| match **t { @@ -238,9 +238,9 @@ impl<'a> SchemaType<'a> { } match (super_type, sub_type) { - (&NonNullNamed(ref super_name), &NonNullNamed(ref sub_name)) | - (&Named(ref super_name), &Named(ref sub_name)) | - (&Named(ref super_name), &NonNullNamed(ref sub_name)) => + (&NonNullNamed(super_name), &NonNullNamed(sub_name)) | + (&Named(super_name), &Named(sub_name)) | + (&Named(super_name), &NonNullNamed(sub_name)) => self.is_named_subtype(sub_name, super_name), (&NonNullList(ref super_inner), &NonNullList(ref sub_inner)) | (&List(ref super_inner), &List(ref sub_inner)) | @@ -332,7 +332,7 @@ impl fmt::Display for DirectiveLocation { impl<'a> fmt::Display for TypeType<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - TypeType::Concrete(ref t) => f.write_str(&t.name().unwrap()), + TypeType::Concrete(t) => f.write_str(t.name().unwrap()), TypeType::List(ref i) => write!(f, "[{}]", i), TypeType::NonNull(ref i) => write!(f, "{}!", i), } diff --git a/src/schema/schema.rs b/src/schema/schema.rs index 31a70bc4..ad81cb62 100644 --- a/src/schema/schema.rs +++ b/src/schema/schema.rs @@ -125,7 +125,7 @@ graphql_object!(<'a> TypeType<'a>: SchemaType<'a> as "__Type" |&self| { Some(schema.concrete_type_list() .iter() .filter_map(|&ct| - if let &MetaType::Object(ObjectMeta { ref name, ref interface_names, .. }) = ct { + if let MetaType::Object(ObjectMeta { ref name, ref interface_names, .. }) = *ct { if interface_names.contains(&iface_name.to_owned()) { schema.type_by_name(name) } else { None } @@ -159,7 +159,7 @@ graphql_object!(<'a> Field<'a>: SchemaType<'a> as "__Field" |&self| { } field args() -> Vec<&Argument> { - self.arguments.as_ref().map_or_else(|| Vec::new(), |v| v.iter().collect()) + self.arguments.as_ref().map_or_else(Vec::new, |v| v.iter().collect()) } field type(&executor) -> TypeType { diff --git a/src/types/base.rs b/src/types/base.rs index 1b6623f6..54303775 100644 --- a/src/types/base.rs +++ b/src/types/base.rs @@ -300,8 +300,8 @@ fn resolve_selection_set_into( .expect("Type not found in schema"); for selection in selection_set { - match selection { - &Selection::Field(Spanning { item: ref f, start: ref start_pos, .. }) => { + match *selection { + Selection::Field(Spanning { item: ref f, start: ref start_pos, .. }) => { if is_excluded(&f.directives, executor.variables()) { continue; } @@ -316,24 +316,24 @@ fn resolve_selection_set_into( continue; } - let meta_field = meta_type.field_by_name(&f.name.item) + let meta_field = meta_type.field_by_name(f.name.item) .unwrap_or_else(|| panic!(format!("Field {} not found on type {:?}", f.name.item, meta_type.name()))); let exec_vars = executor.variables(); - let mut sub_exec = executor.sub_executor( + let sub_exec = executor.sub_executor( Some(response_name), start_pos.clone(), f.selection_set.as_ref().map(|v| &v[..])); let field_result = instance.resolve_field( - &f.name.item, + f.name.item, &Arguments::new( f.arguments.as_ref().map(|m| m.item.iter().map(|&(ref k, ref v)| (k.item, v.item.clone().into_const(exec_vars))).collect()), &meta_field.arguments), - &mut sub_exec); + &sub_exec); match field_result { Ok(v) => merge_key_into(result, response_name, v), @@ -343,32 +343,32 @@ fn resolve_selection_set_into( } } }, - &Selection::FragmentSpread(Spanning { item: ref spread, .. }) => { + Selection::FragmentSpread(Spanning { item: ref spread, .. }) => { if is_excluded(&spread.directives, executor.variables()) { continue; } - let fragment = &executor.fragment_by_name(&spread.name.item) + let fragment = &executor.fragment_by_name(spread.name.item) .expect("Fragment could not be found"); resolve_selection_set_into( instance, &fragment.selection_set[..], executor, result); }, - &Selection::InlineFragment(Spanning { item: ref fragment, start: ref start_pos, .. }) => { + Selection::InlineFragment(Spanning { item: ref fragment, start: ref start_pos, .. }) => { if is_excluded(&fragment.directives, executor.variables()) { continue; } - let mut sub_exec = executor.sub_executor( + let sub_exec = executor.sub_executor( None, start_pos.clone(), Some(&fragment.selection_set[..])); - if let &Some(ref type_condition) = &fragment.type_condition { + if let Some(ref type_condition) = fragment.type_condition { let sub_result = instance.resolve_into_type( - &type_condition.item, + type_condition.item, Some(&fragment.selection_set[..]), - &mut sub_exec); + &sub_exec); if let Ok(Value::Object(mut hash_map)) = sub_result { for (k, v) in hash_map.drain() { @@ -383,7 +383,7 @@ fn resolve_selection_set_into( resolve_selection_set_into( instance, &fragment.selection_set[..], - &mut sub_exec, + &sub_exec, result); } }, @@ -399,19 +399,13 @@ fn is_excluded(directives: &Option>>, vars: &Variables) .flat_map(|v| v.item.clone().into_const(vars).convert()) .next().unwrap(); - if directive.name.item == "skip" && condition { - return true - } - else if directive.name.item == "include" && !condition { + if (directive.name.item == "skip" && condition) || + (directive.name.item == "include" && !condition) { return true } } - - false - } - else { - false } + false } fn merge_key_into( diff --git a/src/types/utilities.rs b/src/types/utilities.rs index 48c28c7d..e50263b8 100644 --- a/src/types/utilities.rs +++ b/src/types/utilities.rs @@ -22,28 +22,28 @@ pub fn is_valid_literal_value(schema: &SchemaType, arg_type: &TypeType, arg_valu TypeType::Concrete(t) => { // Even though InputValue::String can be parsed into an enum, they // are not valid as enum *literals* in a GraphQL query. - match (arg_value, arg_type.to_concrete()) { - (&InputValue::String(_), Some(&MetaType::Enum(EnumMeta { .. }))) => return false, - _ => () + if let (&InputValue::String(_), Some(&MetaType::Enum(EnumMeta { .. }))) + = (arg_value, arg_type.to_concrete()) { + return false; } match *arg_value { - InputValue::Null => true, + InputValue::Null | + InputValue::Variable(_) => true, ref v @ InputValue::Int(_) | ref v @ InputValue::Float(_) | ref v @ InputValue::String(_) | ref v @ InputValue::Boolean(_) | ref v @ InputValue::Enum(_) => { - if let Some(ref parse_fn) = t.input_value_parse_fn() { - parse_fn(&v) + if let Some(parse_fn) = t.input_value_parse_fn() { + parse_fn(v) } else { false } }, InputValue::List(_) => false, - InputValue::Variable(_) => true, InputValue::Object(ref obj) => { - if let &MetaType::InputObject(InputObjectMeta { ref input_fields, .. }) = t { + if let MetaType::InputObject(InputObjectMeta { ref input_fields, .. }) = *t { let mut remaining_required_fields = input_fields.iter() .filter_map(|f| if f.arg_type.is_non_null() { Some(&f.name) } else { None }) .collect::>(); diff --git a/src/validation/context.rs b/src/validation/context.rs index 736362d5..a4f9b541 100644 --- a/src/validation/context.rs +++ b/src/validation/context.rs @@ -97,7 +97,7 @@ impl<'a> ValidatorContext<'a> { self.type_stack.push(None); } - self.type_literal_stack.push(t.map(|t| t.clone())); + self.type_literal_stack.push(t.cloned()); let res = f(self); @@ -131,7 +131,7 @@ impl<'a> ValidatorContext<'a> { self.input_type_stack.push(None); } - self.input_type_literal_stack.push(t.map(|t| t.clone())); + self.input_type_literal_stack.push(t.cloned()); let res = f(self); diff --git a/src/validation/input_value.rs b/src/validation/input_value.rs index aec372fd..02a19a80 100644 --- a/src/validation/input_value.rs +++ b/src/validation/input_value.rs @@ -25,7 +25,7 @@ pub fn validate_input_values( let mut errs = vec![]; for def in document { - if let &Definition::Operation(ref op) = def { + if let Definition::Operation(ref op) = *def { if let Some(ref vars) = op.item.variable_definitions { validate_var_defs(values, &vars.item, schema, &mut errs); } @@ -56,8 +56,8 @@ fn validate_var_defs( ), &[ name.start.clone() ], )); - } else if let Some(ref v) = values.get(name.item) { - unify_value(&name.item, &name.start, v, &ct, schema, errors, Path::Root); + } else if let Some(v) = values.get(name.item) { + unify_value(name.item, &name.start, v, &ct, schema, errors, Path::Root); } }, _ => errors.push(RuleError::new( @@ -89,7 +89,7 @@ fn unify_value<'a>( ); } else { - unify_value(var_name, var_pos, value, &inner, schema, errors, path); + unify_value(var_name, var_pos, value, inner, schema, errors, path); } } @@ -101,9 +101,9 @@ fn unify_value<'a>( match value.to_list_value() { Some(l) => for (i, v) in l.iter().enumerate() { - unify_value(var_name, var_pos, v, &inner, schema, errors, Path::ArrayElement(i, &path)); + unify_value(var_name, var_pos, v, inner, schema, errors, Path::ArrayElement(i, &path)); }, - _ => unify_value(var_name, var_pos, value, &inner, schema, errors, path) + _ => unify_value(var_name, var_pos, value, inner, schema, errors, path) } } @@ -112,12 +112,12 @@ fn unify_value<'a>( return; } - match mt { - &MetaType::Scalar(ref sm) => + match *mt { + MetaType::Scalar(ref sm) => unify_scalar(var_name, var_pos, value, sm, errors, &path), - &MetaType::Enum(ref em) => + MetaType::Enum(ref em) => unify_enum(var_name, var_pos, value, em, errors, &path), - &MetaType::InputObject(ref iom) => + MetaType::InputObject(ref iom) => unify_input_object(var_name, var_pos, value, iom, schema, errors, &path), _ => panic!("Can't unify non-input concrete type"), } @@ -133,8 +133,8 @@ fn unify_scalar<'a>( errors: &mut Vec, path: &Path<'a>, ) { - match value { - &InputValue::List(_) => + match *value { + InputValue::List(_) => push_unification_error( errors, var_name, @@ -142,7 +142,7 @@ fn unify_scalar<'a>( path, &format!(r#"Expected "{}", found list"#, meta.name), ), - &InputValue::Object(_) => + InputValue::Object(_) => push_unification_error( errors, var_name, @@ -162,8 +162,8 @@ fn unify_enum<'a>( errors: &mut Vec, path: &Path<'a>, ) { - match value { - &InputValue::String(ref name) | &InputValue::Enum(ref name) => { + match *value { + InputValue::String(ref name) | InputValue::Enum(ref name) => { if !meta.values.iter().any(|ev| &ev.name == name) { push_unification_error( errors, @@ -200,7 +200,7 @@ fn unify_input_object<'a>( let mut has_value = false; keys.remove(&input_field.name.as_str()); - if let Some(ref value) = obj.get(input_field.name.as_str()) { + if let Some(value) = obj.get(input_field.name.as_str()) { if !value.is_null() { has_value = true; @@ -232,8 +232,8 @@ fn unify_input_object<'a>( errors, var_name, var_pos, - &Path::ObjectField(&key, path), - &format!("Unknown field"), + &Path::ObjectField(key, path), + "Unknown field", ); } } diff --git a/src/validation/multi_visitor.rs b/src/validation/multi_visitor.rs index f0e3de8d..147ab710 100644 --- a/src/validation/multi_visitor.rs +++ b/src/validation/multi_visitor.rs @@ -17,7 +17,7 @@ impl<'a> MultiVisitor<'a> { } fn visit_all + 'a>) -> ()>(&mut self, mut f: F) { - for mut v in self.visitors.iter_mut() { + for mut v in &mut self.visitors { f(v); } } diff --git a/src/validation/rules/arguments_of_correct_type.rs b/src/validation/rules/arguments_of_correct_type.rs index 510f593f..03dc9cef 100644 --- a/src/validation/rules/arguments_of_correct_type.rs +++ b/src/validation/rules/arguments_of_correct_type.rs @@ -17,7 +17,7 @@ pub fn factory<'a>() -> ArgumentsOfCorrectType<'a> { impl<'a> Visitor<'a> for ArgumentsOfCorrectType<'a> { fn enter_directive(&mut self, ctx: &mut ValidatorContext<'a>, directive: &'a Spanning) { self.current_args = ctx.schema - .directive_by_name(&directive.item.name.item) + .directive_by_name(directive.item.name.item) .map(|d| &d.arguments); } @@ -27,7 +27,7 @@ impl<'a> Visitor<'a> for ArgumentsOfCorrectType<'a> { fn enter_field(&mut self, ctx: &mut ValidatorContext<'a>, field: &'a Spanning) { self.current_args = ctx.parent_type() - .and_then(|t| t.field_by_name(&field.item.name.item)) + .and_then(|t| t.field_by_name(field.item.name.item)) .and_then(|f| f.arguments.as_ref()); } @@ -37,13 +37,13 @@ impl<'a> Visitor<'a> for ArgumentsOfCorrectType<'a> { fn enter_argument(&mut self, ctx: &mut ValidatorContext<'a>, &(ref arg_name, ref arg_value): &'a (Spanning<&'a str>, Spanning)) { if let Some(argument_meta) = self.current_args - .and_then(|args| args.iter().filter(|a| a.name == arg_name.item).next()) + .and_then(|args| args.iter().find(|a| a.name == arg_name.item)) { let meta_type = ctx.schema.make_type(&argument_meta.arg_type); - if !is_valid_literal_value(&ctx.schema, &meta_type, &arg_value.item) { + if !is_valid_literal_value(ctx.schema, &meta_type, &arg_value.item) { ctx.report_error( - &error_message(&arg_name.item, &format!("{}", argument_meta.arg_type)), + &error_message(arg_name.item, &format!("{}", argument_meta.arg_type)), &[arg_value.start.clone()]); } } diff --git a/src/validation/rules/default_values_of_correct_type.rs b/src/validation/rules/default_values_of_correct_type.rs index 09f2096a..7082bfe8 100644 --- a/src/validation/rules/default_values_of_correct_type.rs +++ b/src/validation/rules/default_values_of_correct_type.rs @@ -16,15 +16,15 @@ impl<'a> Visitor<'a> for DefaultValuesOfCorrectType { if let Some(Spanning { item: ref var_value, ref start, .. }) = var_def.default_value { if var_def.var_type.item.is_non_null() { ctx.report_error( - &non_null_error_message(&var_name.item, &format!("{}", var_def.var_type.item)), + &non_null_error_message(var_name.item, &format!("{}", var_def.var_type.item)), &[start.clone()]) } else { let meta_type = ctx.schema.make_type(&var_def.var_type.item); - if !is_valid_literal_value(&ctx.schema, &meta_type, var_value) { + if !is_valid_literal_value(ctx.schema, &meta_type, var_value) { ctx.report_error( - &type_error_message(&var_name.item, &format!("{}", var_def.var_type.item)), + &type_error_message(var_name.item, &format!("{}", var_def.var_type.item)), &[start.clone()]); } } diff --git a/src/validation/rules/fields_on_correct_type.rs b/src/validation/rules/fields_on_correct_type.rs index df814083..174d8d53 100644 --- a/src/validation/rules/fields_on_correct_type.rs +++ b/src/validation/rules/fields_on_correct_type.rs @@ -13,11 +13,11 @@ impl<'a> Visitor<'a> for FieldsOnCorrectType { { if let Some(parent_type) = context.parent_type() { let field_name = &field.item.name; - let type_name = parent_type.name().clone().unwrap_or(""); + let type_name = parent_type.name().unwrap_or(""); - if parent_type.field_by_name(&field_name.item).is_none() { + if parent_type.field_by_name(field_name.item).is_none() { context.report_error( - &error_message(&field_name.item, &type_name), + &error_message(field_name.item, type_name), &[field_name.start.clone()]); } } diff --git a/src/validation/rules/fragments_on_composite_types.rs b/src/validation/rules/fragments_on_composite_types.rs index 41159516..bb27a162 100644 --- a/src/validation/rules/fragments_on_composite_types.rs +++ b/src/validation/rules/fragments_on_composite_types.rs @@ -13,13 +13,13 @@ impl<'a> Visitor<'a> for FragmentsOnCompositeTypes { { if let Some(current_type) = context.current_type() { if !current_type.is_composite() { - let type_name = current_type.name().clone().unwrap_or(""); + let type_name = current_type.name().unwrap_or(""); let type_cond = &f.item.type_condition; context.report_error( &error_message( - Some(&f.item.name.item.clone()), - &type_name), + Some(f.item.name.item), + type_name), &[type_cond.start.clone()]); } } @@ -31,12 +31,12 @@ impl<'a> Visitor<'a> for FragmentsOnCompositeTypes { if let Some(ref type_cond) = f.item.type_condition { let invalid_type_name = context.current_type().iter() .filter(|&t| !t.is_composite()) - .map(|t| t.name().clone().unwrap_or("")) + .map(|t| t.name().unwrap_or("")) .next(); if let Some(name) = invalid_type_name { context.report_error( - &error_message(None, &name), + &error_message(None, name), &[type_cond.start.clone()]); } } diff --git a/src/validation/rules/known_argument_names.rs b/src/validation/rules/known_argument_names.rs index 2141e39b..cc1d2b0d 100644 --- a/src/validation/rules/known_argument_names.rs +++ b/src/validation/rules/known_argument_names.rs @@ -22,8 +22,8 @@ pub fn factory<'a>() -> KnownArgumentNames<'a> { impl<'a> Visitor<'a> for KnownArgumentNames<'a> { fn enter_directive(&mut self, ctx: &mut ValidatorContext<'a>, directive: &'a Spanning) { self.current_args = ctx.schema - .directive_by_name(&directive.item.name.item) - .map(|d| (ArgumentPosition::Directive(&directive.item.name.item), &d.arguments)); + .directive_by_name(directive.item.name.item) + .map(|d| (ArgumentPosition::Directive(directive.item.name.item), &d.arguments)); } fn exit_directive(&mut self, _: &mut ValidatorContext<'a>, _: &'a Spanning) { @@ -32,12 +32,12 @@ impl<'a> Visitor<'a> for KnownArgumentNames<'a> { fn enter_field(&mut self, ctx: &mut ValidatorContext<'a>, field: &'a Spanning) { self.current_args = ctx.parent_type() - .and_then(|t| t.field_by_name(&field.item.name.item)) + .and_then(|t| t.field_by_name(field.item.name.item)) .and_then(|f| f.arguments.as_ref()) .map(|args| ( ArgumentPosition::Field( - &field.item.name.item, - &ctx.parent_type().expect("Parent type should exist") + field.item.name.item, + ctx.parent_type().expect("Parent type should exist") .name().expect("Parent type should be named")), args)); } @@ -48,12 +48,12 @@ impl<'a> Visitor<'a> for KnownArgumentNames<'a> { fn enter_argument(&mut self, ctx: &mut ValidatorContext<'a>, &(ref arg_name, _): &'a (Spanning<&'a str>, Spanning)) { if let Some((ref pos, args)) = self.current_args { - if args.iter().filter(|a| a.name == arg_name.item).next().is_none() { + if args.iter().find(|a| a.name == arg_name.item).is_none() { let message = match *pos { - ArgumentPosition::Field(ref field_name, ref type_name) => - field_error_message(&arg_name.item, field_name, type_name), - ArgumentPosition::Directive(ref directive_name) => - directive_error_message(&arg_name.item, directive_name), + ArgumentPosition::Field(field_name, type_name) => + field_error_message(arg_name.item, field_name, type_name), + ArgumentPosition::Directive(directive_name) => + directive_error_message(arg_name.item, directive_name), }; ctx.report_error( diff --git a/src/validation/rules/known_directives.rs b/src/validation/rules/known_directives.rs index f000a79a..3b70d2db 100644 --- a/src/validation/rules/known_directives.rs +++ b/src/validation/rules/known_directives.rs @@ -67,7 +67,7 @@ impl<'a> Visitor<'a> for KnownDirectives { if let Some(directive_type) = ctx.schema.directive_by_name(directive_name) { if let Some(current_location) = self.location_stack.last() { - if directive_type.locations.iter().filter(|l| l == ¤t_location).next().is_none() { + if directive_type.locations.iter().find(|l| l == ¤t_location).is_none() { ctx.report_error( &misplaced_error_message(directive_name, current_location), &[directive.start.clone()]); diff --git a/src/validation/rules/known_fragment_names.rs b/src/validation/rules/known_fragment_names.rs index 77d60a5b..7fd28ab5 100644 --- a/src/validation/rules/known_fragment_names.rs +++ b/src/validation/rules/known_fragment_names.rs @@ -11,9 +11,9 @@ pub fn factory() -> KnownFragmentNames { impl<'a> Visitor<'a> for KnownFragmentNames { fn enter_fragment_spread(&mut self, context: &mut ValidatorContext<'a>, spread: &'a Spanning) { let spread_name = &spread.item.name; - if !context.is_known_fragment(&spread_name.item) { + if !context.is_known_fragment(spread_name.item) { context.report_error( - &error_message(&spread_name.item), + &error_message(spread_name.item), &[spread_name.start.clone()]); } } diff --git a/src/validation/rules/known_type_names.rs b/src/validation/rules/known_type_names.rs index 4072798c..198ddb36 100644 --- a/src/validation/rules/known_type_names.rs +++ b/src/validation/rules/known_type_names.rs @@ -11,18 +11,18 @@ pub fn factory() -> KnownTypeNames { impl<'a> Visitor<'a> for KnownTypeNames { fn enter_inline_fragment(&mut self, ctx: &mut ValidatorContext<'a>, fragment: &'a Spanning) { if let Some(ref type_cond) = fragment.item.type_condition { - validate_type(ctx, &type_cond.item, &type_cond.start); + validate_type(ctx, type_cond.item, &type_cond.start); } } fn enter_fragment_definition(&mut self, ctx: &mut ValidatorContext<'a>, fragment: &'a Spanning) { let type_cond = &fragment.item.type_condition; - validate_type(ctx, &type_cond.item, &type_cond.start); + validate_type(ctx, type_cond.item, &type_cond.start); } fn enter_variable_definition(&mut self, ctx: &mut ValidatorContext<'a>, &(_, ref var_def): &'a (Spanning<&'a str>, VariableDefinition)) { let type_name = var_def.var_type.item.innermost_name(); - validate_type(ctx, &type_name, &var_def.var_type.start); + validate_type(ctx, type_name, &var_def.var_type.start); } } diff --git a/src/validation/rules/no_fragment_cycles.rs b/src/validation/rules/no_fragment_cycles.rs index a14d91be..23df5fb0 100644 --- a/src/validation/rules/no_fragment_cycles.rs +++ b/src/validation/rules/no_fragment_cycles.rs @@ -50,8 +50,8 @@ impl<'a> Visitor<'a> for NoFragmentCycles<'a> { assert!(self.current_fragment.is_none()); let fragment_name = &fragment.item.name.item; - self.current_fragment = Some(&fragment_name); - self.fragment_order.push(&fragment_name); + self.current_fragment = Some(fragment_name); + self.fragment_order.push(fragment_name); } fn exit_fragment_definition(&mut self, _: &mut ValidatorContext<'a>, fragment: &'a Spanning) { @@ -60,14 +60,14 @@ impl<'a> Visitor<'a> for NoFragmentCycles<'a> { } fn enter_fragment_spread(&mut self, _: &mut ValidatorContext<'a>, spread: &'a Spanning) { - if let Some(ref current_fragment) = self.current_fragment { + if let Some(current_fragment) = self.current_fragment { self.spreads - .entry(¤t_fragment) - .or_insert_with(|| vec![]) + .entry(current_fragment) + .or_insert_with(Vec::new) .push(Spanning::start_end( &spread.start.clone(), &spread.end.clone(), - &spread.item.name.item)); + spread.item.name.item)); } } } @@ -84,7 +84,7 @@ impl<'a> CycleDetector<'a> { for node in &self.spreads[from] { let name = &node.item; - let index = self.path_indices.get(name).map(|i| *i); + let index = self.path_indices.get(name).cloned(); if let Some(index) = index { let err_pos = if index < path.len() { diff --git a/src/validation/rules/no_undefined_variables.rs b/src/validation/rules/no_undefined_variables.rs index 89c9ca42..afedc89f 100644 --- a/src/validation/rules/no_undefined_variables.rs +++ b/src/validation/rules/no_undefined_variables.rs @@ -43,7 +43,7 @@ impl<'a> NoUndefinedVariables<'a> { if let Some(spreads) = self.spreads.get(scope) { for spread in spreads { - self.find_undef_vars(&Scope::Fragment(spread.clone()), defined, unused, visited); + self.find_undef_vars(&Scope::Fragment(spread), defined, unused, visited); } } } @@ -54,12 +54,12 @@ impl<'a> Visitor<'a> for NoUndefinedVariables<'a> { for (op_name, &(ref pos, ref def_vars)) in &self.defined_variables { let mut unused = Vec::new(); let mut visited = HashSet::new(); - self.find_undef_vars(&Scope::Operation(op_name.clone()), &def_vars, &mut unused, &mut visited); + self.find_undef_vars(&Scope::Operation(*op_name), def_vars, &mut unused, &mut visited); ctx.append_errors(unused .into_iter() .map(|var| RuleError::new( - &error_message(&var.item, op_name.clone()), + &error_message(var.item, *op_name), &[ var.start.clone(), pos.clone() @@ -75,21 +75,21 @@ impl<'a> Visitor<'a> for NoUndefinedVariables<'a> { } fn enter_fragment_definition(&mut self, _: &mut ValidatorContext<'a>, f: &'a Spanning) { - self.current_scope = Some(Scope::Fragment(&f.item.name.item)); + self.current_scope = Some(Scope::Fragment(f.item.name.item)); } fn enter_fragment_spread(&mut self, _: &mut ValidatorContext<'a>, spread: &'a Spanning) { if let Some(ref scope) = self.current_scope { self.spreads.entry(scope.clone()) - .or_insert_with(|| Vec::new()) - .push(&spread.item.name.item); + .or_insert_with(Vec::new) + .push(spread.item.name.item); } } fn enter_variable_definition(&mut self, _: &mut ValidatorContext<'a>, &(ref var_name, _): &'a (Spanning<&'a str>, VariableDefinition)) { if let Some(Scope::Operation(ref name)) = self.current_scope { if let Some(&mut (_, ref mut vars)) = self.defined_variables.get_mut(name) { - vars.insert(&var_name.item); + vars.insert(var_name.item); } } } @@ -98,7 +98,7 @@ impl<'a> Visitor<'a> for NoUndefinedVariables<'a> { if let Some(ref scope) = self.current_scope { self.used_variables .entry(scope.clone()) - .or_insert_with(|| Vec::new()) + .or_insert_with(Vec::new) .append(&mut value.item .referenced_variables() .iter() diff --git a/src/validation/rules/no_unused_fragments.rs b/src/validation/rules/no_unused_fragments.rs index f96a0e4d..03accf08 100644 --- a/src/validation/rules/no_unused_fragments.rs +++ b/src/validation/rules/no_unused_fragments.rs @@ -26,7 +26,7 @@ pub fn factory<'a>() -> NoUnusedFragments<'a> { impl<'a> NoUnusedFragments<'a> { fn find_reachable_fragments(&self, from: &Scope<'a>, result: &mut HashSet<&'a str>) { - if let Scope::Fragment(ref name) = *from { + if let Scope::Fragment(name) = *from { if result.contains(name) { return; } @@ -37,7 +37,7 @@ impl<'a> NoUnusedFragments<'a> { if let Some(spreads) = self.spreads.get(from) { for spread in spreads { - self.find_reachable_fragments(&Scope::Fragment(spread.clone()), result) + self.find_reachable_fragments(&Scope::Fragment(spread), result) } } } @@ -57,7 +57,7 @@ impl<'a> Visitor<'a> for NoUnusedFragments<'a> { for fragment in &self.defined_fragments { if !reachable.contains(&fragment.item) { ctx.report_error( - &error_message(&fragment.item), + &error_message(fragment.item), &[fragment.start.clone()]); } } @@ -69,18 +69,18 @@ impl<'a> Visitor<'a> for NoUnusedFragments<'a> { } fn enter_fragment_definition(&mut self, _: &mut ValidatorContext<'a>, f: &'a Spanning) { - self.current_scope = Some(Scope::Fragment(&f.item.name.item)); + self.current_scope = Some(Scope::Fragment(f.item.name.item)); self.defined_fragments.insert(Spanning::start_end( &f.start, &f.end, - &f.item.name.item)); + f.item.name.item)); } fn enter_fragment_spread(&mut self, _: &mut ValidatorContext<'a>, spread: &'a Spanning) { if let Some(ref scope) = self.current_scope { self.spreads.entry(scope.clone()) - .or_insert_with(|| Vec::new()) - .push(&spread.item.name.item); + .or_insert_with(Vec::new) + .push(spread.item.name.item); } } } diff --git a/src/validation/rules/no_unused_variables.rs b/src/validation/rules/no_unused_variables.rs index 953f43a5..d378280b 100644 --- a/src/validation/rules/no_unused_variables.rs +++ b/src/validation/rules/no_unused_variables.rs @@ -43,7 +43,7 @@ impl<'a> NoUnusedVariables<'a> { if let Some(spreads) = self.spreads.get(from) { for spread in spreads { - self.find_used_vars(&Scope::Fragment(spread.clone()), defined, used, visited); + self.find_used_vars(&Scope::Fragment(spread), defined, used, visited); } } } @@ -55,7 +55,7 @@ impl<'a> Visitor<'a> for NoUnusedVariables<'a> { let mut used = HashSet::new(); let mut visited = HashSet::new(); self.find_used_vars( - &Scope::Operation(op_name.clone()), + &Scope::Operation(*op_name), &def_vars.iter().map(|def| def.item).collect(), &mut used, &mut visited); @@ -64,7 +64,7 @@ impl<'a> Visitor<'a> for NoUnusedVariables<'a> { .iter() .filter(|var| !used.contains(var.item)) .map(|var| RuleError::new( - &error_message(&var.item, op_name.clone()), + &error_message(var.item, *op_name), &[var.start.clone()])) .collect()); } @@ -72,19 +72,19 @@ impl<'a> Visitor<'a> for NoUnusedVariables<'a> { fn enter_operation_definition(&mut self, _: &mut ValidatorContext<'a>, op: &'a Spanning) { let op_name = op.item.name.as_ref().map(|s| s.item); - self.current_scope = Some(Scope::Operation(op_name.clone())); + self.current_scope = Some(Scope::Operation(op_name)); self.defined_variables.insert(op_name, HashSet::new()); } fn enter_fragment_definition(&mut self, _: &mut ValidatorContext<'a>, f: &'a Spanning) { - self.current_scope = Some(Scope::Fragment(&f.item.name.item)); + self.current_scope = Some(Scope::Fragment(f.item.name.item)); } fn enter_fragment_spread(&mut self, _: &mut ValidatorContext<'a>, spread: &'a Spanning) { if let Some(ref scope) = self.current_scope { self.spreads.entry(scope.clone()) - .or_insert_with(|| Vec::new()) - .push(&spread.item.name.item); + .or_insert_with(Vec::new) + .push(spread.item.name.item); } } @@ -100,7 +100,7 @@ impl<'a> Visitor<'a> for NoUnusedVariables<'a> { if let Some(ref scope) = self.current_scope { self.used_variables .entry(scope.clone()) - .or_insert_with(|| Vec::new()) + .or_insert_with(Vec::new) .append(&mut value.item.referenced_variables()); } } diff --git a/src/validation/rules/overlapping_fields_can_be_merged.rs b/src/validation/rules/overlapping_fields_can_be_merged.rs index 2e0a956e..a5fb044b 100644 --- a/src/validation/rules/overlapping_fields_can_be_merged.rs +++ b/src/validation/rules/overlapping_fields_can_be_merged.rs @@ -46,7 +46,7 @@ impl OrderedMap { } } - fn iter<'a>(&'a self) -> OrderedMapIter<'a, K, V> { + fn iter(&self) -> OrderedMapIter { OrderedMapIter { map: &self.data, inner: self.insert_order.iter(), @@ -106,11 +106,11 @@ impl<'a> PairSet<'a> { fn insert(&mut self, a: &'a str, b: &'a str, mutex: bool) { self.data.entry(a) - .or_insert_with(|| HashMap::new()) + .or_insert_with(HashMap::new) .insert(b, mutex); self.data.entry(b) - .or_insert_with(|| HashMap::new()) + .or_insert_with(HashMap::new) .insert(a, mutex); } } @@ -146,15 +146,15 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> { self.collect_conflicts_between_fields_and_fragment( &mut conflicts, &field_map, - &frag_name1, + frag_name1, false, ctx); for frag_name2 in &fragment_names[i+1..] { self.collect_conflicts_between_fragments( &mut conflicts, - &frag_name1, - &frag_name2, + frag_name1, + frag_name2, false, ctx); } @@ -252,7 +252,7 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> { self.collect_conflicts_between_fields_and_fragment( conflicts, field_map, - &fragment_name2, + fragment_name2, mutually_exclusive, ctx); } @@ -271,7 +271,7 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> { if let Some(fields2) = field_map2.get(response_name) { for field1 in fields1 { for field2 in fields2 { - if let Some(conflict) = self.find_conflict(&response_name, field1, field2, mutually_exclusive, ctx) { + if let Some(conflict) = self.find_conflict(response_name, field1, field2, mutually_exclusive, ctx) { conflicts.push(conflict); } } @@ -290,7 +290,7 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> { for (response_name, fields) in field_map.iter() { for (i, field1) in fields.iter().enumerate() { for field2 in &fields[i+1..] { - if let Some(conflict) = self.find_conflict(&response_name, field1, field2, false, ctx) { + if let Some(conflict) = self.find_conflict(response_name, field1, field2, false, ctx) { conflicts.push(conflict); } } @@ -308,13 +308,13 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> { ) -> Option { - let AstAndDef(ref parent_type1, ref ast1, ref def1) = *field1; - let AstAndDef(ref parent_type2, ref ast2, ref def2) = *field2; + let AstAndDef(ref parent_type1, ast1, ref def1) = *field1; + let AstAndDef(ref parent_type2, ast2, ref def2) = *field2; let mutually_exclusive = parents_mutually_exclusive || (parent_type1 != parent_type2 - && self.is_object_type(ctx, parent_type1.clone()) - && self.is_object_type(ctx, parent_type2.clone())); + && self.is_object_type(ctx, *parent_type1) + && self.is_object_type(ctx, *parent_type2)); if !mutually_exclusive { let name1 = &ast1.item.name.item; @@ -345,7 +345,7 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> { let t2 = def2.as_ref().map(|def| &def.field_type); if let (Some(t1), Some(t2)) = (t1, t2) { - if self.is_type_conflict(ctx, &t1, &t2) { + if self.is_type_conflict(ctx, t1, t2) { return Some(Conflict( ConflictReason( response_name.to_owned(), @@ -360,9 +360,9 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> { let conflicts = self.find_conflicts_between_sub_selection_sets( mutually_exclusive, t1.map(|t| t.innermost_name()), - &s1, + s1, t2.map(|t| t.innermost_name()), - &s2, + s2, ctx); return self.subfield_conflicts( @@ -467,12 +467,11 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> { -> bool { match (t1, t2) { - (&Type::List(ref inner1), &Type::List(ref inner2)) => - self.is_type_conflict(ctx, inner1, inner2), + (&Type::List(ref inner1), &Type::List(ref inner2)) | (&Type::NonNullList(ref inner1), &Type::NonNullList(ref inner2)) => self.is_type_conflict(ctx, inner1, inner2), - (&Type::NonNullNamed(ref n1), &Type::NonNullNamed(ref n2)) | - (&Type::Named(ref n1), &Type::Named(ref n2)) => { + (&Type::NonNullNamed(n1), &Type::NonNullNamed(n2)) | + (&Type::Named(n1), &Type::Named(n2)) => { let ct1 = ctx.schema.concrete_type_by_name(n1); let ct2 = ctx.schema.concrete_type_by_name(n2); @@ -504,7 +503,7 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> { } args1.iter().all(|&(ref n1, ref v1)| { - if let Some(&(_, ref v2)) = args2.iter().filter(|&&(ref n2, _)| n1.item == n2.item).next() { + if let Some(&(_, ref v2)) = args2.iter().find(|&&(ref n2, _)| n1.item == n2.item) { v1.item.unlocated_eq(&v2.item) } else { @@ -536,7 +535,7 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> { ) -> (AstAndDefCollection<'a>, Vec<&'a str>) { - let fragment_type = ctx.schema.concrete_type_by_name(&fragment.type_condition.item); + let fragment_type = ctx.schema.concrete_type_by_name(fragment.type_condition.item); self.get_fields_and_fragment_names(fragment_type, &fragment.selection_set, ctx) } @@ -571,7 +570,7 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> { Selection::Field(ref f) => { let field_name = &f.item.name.item; let field_def = parent_type.and_then(|t| t.field_by_name(field_name)); - let response_name = f.item.alias.as_ref().map(|s| &s.item).unwrap_or_else(|| &field_name); + let response_name = f.item.alias.as_ref().map(|s| &s.item).unwrap_or(field_name); if !ast_and_defs.contains_key(response_name) { ast_and_defs.insert(response_name, Vec::new()); @@ -581,13 +580,13 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> { .push(AstAndDef(parent_type.and_then(MetaType::name), f, field_def)); }, Selection::FragmentSpread(Spanning { item: FragmentSpread { ref name, ..}, ..}) => { - if fragment_names.iter().filter(|n| *n == &name.item).next().is_none() { - fragment_names.push(&name.item); + if fragment_names.iter().find(|n| *n == &name.item).is_none() { + fragment_names.push(name.item); } }, Selection::InlineFragment(Spanning { item: ref inline, .. }) => { let parent_type = inline.type_condition.as_ref() - .and_then(|cond| ctx.schema.concrete_type_by_name(&cond.item)) + .and_then(|cond| ctx.schema.concrete_type_by_name(cond.item)) .or(parent_type); self.collect_fields_and_fragment_names(parent_type, &inline.selection_set, ctx, ast_and_defs, fragment_names); @@ -601,7 +600,7 @@ impl<'a> Visitor<'a> for OverlappingFieldsCanBeMerged<'a> { fn enter_document(&mut self, _: &mut ValidatorContext<'a>, defs: &'a Document) { for def in defs { if let Definition::Fragment(Spanning { ref item, .. }) = *def { - self.named_fragments.insert(&item.name.item, &item); + self.named_fragments.insert(item.name.item, item); } } } diff --git a/src/validation/rules/possible_fragment_spreads.rs b/src/validation/rules/possible_fragment_spreads.rs index 1bc219e8..71730f76 100644 --- a/src/validation/rules/possible_fragment_spreads.rs +++ b/src/validation/rules/possible_fragment_spreads.rs @@ -18,16 +18,16 @@ impl<'a> Visitor<'a> for PossibleFragmentSpreads<'a> { fn enter_document(&mut self, ctx: &mut ValidatorContext<'a>, defs: &'a Document) { for def in defs { if let Definition::Fragment(Spanning { ref item, .. }) = *def { - if let Some(t) = ctx.schema.concrete_type_by_name(&item.type_condition.item) { - self.fragment_types.insert(&item.name.item, t); + if let Some(t) = ctx.schema.concrete_type_by_name(item.type_condition.item) { + self.fragment_types.insert(item.name.item, t); } } } } fn enter_inline_fragment(&mut self, ctx: &mut ValidatorContext<'a>, frag: &'a Spanning) { - if let (Some(ref parent_type), Some(ref frag_type)) - = (ctx.parent_type(), frag.item.type_condition.as_ref().and_then(|s| ctx.schema.concrete_type_by_name(&s.item))) + if let (Some(parent_type), Some(frag_type)) + = (ctx.parent_type(), frag.item.type_condition.as_ref().and_then(|s| ctx.schema.concrete_type_by_name(s.item))) { if !ctx.schema.type_overlap(parent_type, frag_type) { ctx.report_error( @@ -41,13 +41,13 @@ impl<'a> Visitor<'a> for PossibleFragmentSpreads<'a> { } fn enter_fragment_spread(&mut self, ctx: &mut ValidatorContext<'a>, spread: &'a Spanning) { - if let (Some(ref parent_type), Some(ref frag_type)) + if let (Some(parent_type), Some(frag_type)) = (ctx.parent_type(), self.fragment_types.get(spread.item.name.item)) { if !ctx.schema.type_overlap(parent_type, frag_type) { ctx.report_error( &error_message( - Some(&spread.item.name.item), + Some(spread.item.name.item), parent_type.name().unwrap_or(""), frag_type.name().unwrap_or("")), &[spread.start.clone()]); diff --git a/src/validation/rules/unique_argument_names.rs b/src/validation/rules/unique_argument_names.rs index be84a884..54e9dfb7 100644 --- a/src/validation/rules/unique_argument_names.rs +++ b/src/validation/rules/unique_argument_names.rs @@ -24,10 +24,10 @@ impl<'a> Visitor<'a> for UniqueArgumentNames<'a> { } fn enter_argument(&mut self, ctx: &mut ValidatorContext<'a>, &(ref arg_name, _): &'a (Spanning<&'a str>, Spanning)) { - match self.known_names.entry(&arg_name.item) { + match self.known_names.entry(arg_name.item) { Entry::Occupied(e) => { ctx.report_error( - &error_message(&arg_name.item), + &error_message(arg_name.item), &[e.get().clone(), arg_name.start.clone()]); } Entry::Vacant(e) => { diff --git a/src/validation/rules/unique_fragment_names.rs b/src/validation/rules/unique_fragment_names.rs index e14c8135..f966d39e 100644 --- a/src/validation/rules/unique_fragment_names.rs +++ b/src/validation/rules/unique_fragment_names.rs @@ -16,10 +16,10 @@ pub fn factory<'a>() -> UniqueFragmentNames<'a> { impl<'a> Visitor<'a> for UniqueFragmentNames<'a> { fn enter_fragment_definition(&mut self, context: &mut ValidatorContext<'a>, f: &'a Spanning) { - match self.names.entry(&f.item.name.item) { + match self.names.entry(f.item.name.item) { Entry::Occupied(e) => { context.report_error( - &duplicate_message(&f.item.name.item), + &duplicate_message(f.item.name.item), &[e.get().clone(), f.item.name.start.clone()]); } Entry::Vacant(e) => { diff --git a/src/validation/rules/unique_operation_names.rs b/src/validation/rules/unique_operation_names.rs index b0e06717..6e99096b 100644 --- a/src/validation/rules/unique_operation_names.rs +++ b/src/validation/rules/unique_operation_names.rs @@ -16,11 +16,11 @@ pub fn factory<'a>() -> UniqueOperationNames<'a> { impl<'a> Visitor<'a> for UniqueOperationNames<'a> { fn enter_operation_definition(&mut self, ctx: &mut ValidatorContext<'a>, op: &'a Spanning) { - if let &Some(ref op_name) = &op.item.name { - match self.names.entry(&op_name.item) { + if let Some(ref op_name) = op.item.name { + match self.names.entry(op_name.item) { Entry::Occupied(e) => { ctx.report_error( - &error_message(&op_name.item), + &error_message(op_name.item), &[e.get().clone(), op.start.clone()]); } Entry::Vacant(e) => { diff --git a/src/validation/rules/unique_variable_names.rs b/src/validation/rules/unique_variable_names.rs index c80cb14d..bf81dcc6 100644 --- a/src/validation/rules/unique_variable_names.rs +++ b/src/validation/rules/unique_variable_names.rs @@ -20,10 +20,10 @@ impl<'a> Visitor<'a> for UniqueVariableNames<'a> { } fn enter_variable_definition(&mut self, ctx: &mut ValidatorContext<'a>, &(ref var_name, _): &'a (Spanning<&'a str>, VariableDefinition)) { - match self.names.entry(&var_name.item) { + match self.names.entry(var_name.item) { Entry::Occupied(e) => { ctx.report_error( - &error_message(&var_name.item), + &error_message(var_name.item), &[e.get().clone(), var_name.start.clone()]); } Entry::Vacant(e) => { diff --git a/src/validation/rules/variables_are_input_types.rs b/src/validation/rules/variables_are_input_types.rs index 65eec493..5137110b 100644 --- a/src/validation/rules/variables_are_input_types.rs +++ b/src/validation/rules/variables_are_input_types.rs @@ -13,7 +13,7 @@ impl<'a> Visitor<'a> for UniqueVariableNames { if let Some(var_type) = ctx.schema.concrete_type_by_name(var_def.var_type.item.innermost_name()) { if !var_type.is_input() { ctx.report_error( - &error_message(&var_name.item, &format!("{}", var_def.var_type.item)), + &error_message(var_name.item, &format!("{}", var_def.var_type.item)), &[var_def.var_type.start.clone()]); } } diff --git a/src/validation/rules/variables_in_allowed_position.rs b/src/validation/rules/variables_in_allowed_position.rs index ceb30408..b9f396ce 100644 --- a/src/validation/rules/variables_in_allowed_position.rs +++ b/src/validation/rules/variables_in_allowed_position.rs @@ -45,18 +45,17 @@ impl<'a> VariableInAllowedPosition<'a> { for &(ref var_name, ref var_type) in usages { if let Some(&&(ref var_def_name, ref var_def)) = var_defs .iter() - .filter(|&&&(ref n, _)| &n.item == var_name.item) - .next() + .find(|&&&(ref n, _)| &n.item == var_name.item) { let expected_type = match (&var_def.default_value, &var_def.var_type.item) { (&Some(_), &Type::List(ref inner)) => Type::NonNullList(inner.clone()), - (&Some(_), &Type::Named(ref inner)) => Type::NonNullNamed(inner.clone()), + (&Some(_), &Type::Named(inner)) => Type::NonNullNamed(inner), (_, t) => t.clone(), }; if !ctx.schema.is_subtype(&expected_type, var_type) { ctx.report_error( - &error_message(&var_name.item, &format!("{}", expected_type), &format!("{}", var_type)), + &error_message(var_name.item, &format!("{}", expected_type), &format!("{}", var_type)), &[var_def_name.start.clone(), var_name.start.clone()]); } } @@ -74,12 +73,12 @@ impl<'a> VariableInAllowedPosition<'a> { impl<'a> Visitor<'a> for VariableInAllowedPosition<'a> { fn exit_document(&mut self, ctx: &mut ValidatorContext<'a>, _: &'a Document) { for (op_scope, var_defs) in &self.variable_defs { - self.collect_incorrect_usages(&op_scope, var_defs, ctx, &mut HashSet::new()); + self.collect_incorrect_usages(op_scope, var_defs, ctx, &mut HashSet::new()); } } fn enter_fragment_definition(&mut self, _: &mut ValidatorContext<'a>, fragment: &'a Spanning) { - self.current_scope = Some(Scope::Fragment(&fragment.item.name.item)); + self.current_scope = Some(Scope::Fragment(fragment.item.name.item)); } fn enter_operation_definition(&mut self, _: &mut ValidatorContext<'a>, op: &'a Spanning) { @@ -90,8 +89,8 @@ impl<'a> Visitor<'a> for VariableInAllowedPosition<'a> { if let Some(ref scope) = self.current_scope { self.spreads .entry(scope.clone()) - .or_insert_with(|| HashSet::new()) - .insert(&spread.item.name.item); + .or_insert_with(HashSet::new) + .insert(spread.item.name.item); } } @@ -99,7 +98,7 @@ impl<'a> Visitor<'a> for VariableInAllowedPosition<'a> { if let Some(ref scope) = self.current_scope { self.variable_defs .entry(scope.clone()) - .or_insert_with(|| Vec::new()) + .or_insert_with(Vec::new) .push(def); } } @@ -108,8 +107,8 @@ impl<'a> Visitor<'a> for VariableInAllowedPosition<'a> { if let (&Some(ref scope), Some(input_type)) = (&self.current_scope, ctx.current_input_type_literal()) { self.variable_usages .entry(scope.clone()) - .or_insert_with(|| Vec::new()) - .push((Spanning::start_end(&var_name.start, &var_name.end, &var_name.item), input_type.clone())); + .or_insert_with(Vec::new) + .push((Spanning::start_end(&var_name.start, &var_name.end, var_name.item), input_type.clone())); } } } diff --git a/src/validation/visitor.rs b/src/validation/visitor.rs index 856be7a3..92b926d1 100644 --- a/src/validation/visitor.rs +++ b/src/validation/visitor.rs @@ -16,7 +16,7 @@ fn visit_definitions<'a, V: Visitor<'a>>(v: &mut V, ctx: &mut ValidatorContext<' for def in d { let def_type = match *def { Definition::Fragment(Spanning { - item: Fragment { type_condition: Spanning { item: ref name, .. }, .. }, .. }) => + item: Fragment { type_condition: Spanning { item: name, .. }, .. }, .. }) => Some(Type::NonNullNamed(name)), Definition::Operation(Spanning { item: Operation { operation_type: OperationType::Query, .. }, .. }) => @@ -84,7 +84,7 @@ fn visit_variable_definitions<'a, V: Visitor<'a>>(v: &mut V, ctx: &mut Validator fn visit_directives<'a, V: Visitor<'a>>(v: &mut V, ctx: &mut ValidatorContext<'a>, directives: &'a Option>>) { if let Some(ref directives) = *directives { for directive in directives { - let directive_arguments = ctx.schema.directive_by_name(&directive.item.name.item).map(|d| &d.arguments); + let directive_arguments = ctx.schema.directive_by_name(directive.item.name.item).map(|d| &d.arguments); v.enter_directive(ctx, directive); visit_arguments(v, ctx, &directive_arguments, &directive.item.arguments); @@ -97,7 +97,7 @@ fn visit_arguments<'a, V: Visitor<'a>>(v: &mut V, ctx: &mut ValidatorContext<'a> if let Some(ref arguments) = *arguments { for argument in arguments.item.iter() { let arg_type = meta_args - .and_then(|args| args.iter().filter(|a| a.name == argument.0.item).next()) + .and_then(|args| args.iter().find(|a| a.name == argument.0.item)) .map(|a| &a.arg_type); ctx.with_pushed_input_type(arg_type, |ctx| { @@ -133,7 +133,7 @@ fn visit_selection<'a, V: Visitor<'a>>(v: &mut V, ctx: &mut ValidatorContext<'a> fn visit_field<'a, V: Visitor<'a>>(v: &mut V, ctx: &mut ValidatorContext<'a>, field: &'a Spanning) { let meta_field = ctx.parent_type() - .and_then(|t| t.field_by_name(&field.item.name.item)); + .and_then(|t| t.field_by_name(field.item.name.item)); let field_type = meta_field.map(|f| &f.field_type); let field_args = meta_field.and_then(|f| f.arguments.as_ref()); @@ -170,7 +170,7 @@ fn visit_inline_fragment<'a, V: Visitor<'a>>(v: &mut V, ctx: &mut ValidatorConte v.exit_inline_fragment(ctx, fragment); }; - if let &Some(Spanning { item: ref type_name, .. }) = &fragment.item.type_condition { + if let Some(Spanning { item: type_name, .. }) = fragment.item.type_condition { ctx.with_pushed_type(Some(&Type::NonNullNamed(type_name)), visit_fn); } else { @@ -186,7 +186,7 @@ fn visit_input_value<'a, V: Visitor<'a>>(v: &mut V, ctx: &mut ValidatorContext<' for field in fields { let inner_type = ctx.current_input_type_literal() .and_then(|t| match *t { - Type::NonNullNamed(ref name) | Type::Named(ref name) => + Type::NonNullNamed(name) | Type::Named(name) => ctx.schema.concrete_type_by_name(name), _ => None, })