From 144ddb752c3e7ae26ddfd9c8e36a68d6fdd9cb92 Mon Sep 17 00:00:00 2001 From: Sunli Date: Fri, 26 Feb 2021 20:05:09 +0800 Subject: [PATCH] Clippy clean --- .../rules/no_undefined_variables.rs | 18 +++++++++--------- src/validation/rules/no_unused_fragments.rs | 2 +- src/validation/rules/no_unused_variables.rs | 6 +++--- .../rules/variables_in_allowed_position.rs | 8 ++++---- src/validation/utils.rs | 2 +- tests/list.rs | 19 +++++++++---------- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/validation/rules/no_undefined_variables.rs b/src/validation/rules/no_undefined_variables.rs index ce9b3f43..f84ab7a0 100644 --- a/src/validation/rules/no_undefined_variables.rs +++ b/src/validation/rules/no_undefined_variables.rs @@ -21,26 +21,26 @@ impl<'a> NoUndefinedVariables<'a> { &'a self, scope: &Scope<'a>, defined: &HashSet<&'a str>, - unused: &mut Vec<(&'a str, Pos)>, + undef: &mut Vec<(&'a str, Pos)>, visited: &mut HashSet>, ) { if visited.contains(scope) { return; } - visited.insert(scope.clone()); + visited.insert(*scope); if let Some(used_vars) = self.used_variables.get(scope) { for (var, pos) in used_vars { if !defined.contains(var) { - unused.push((*var, *pos)); + undef.push((*var, *pos)); } } } if let Some(spreads) = self.spreads.get(scope) { for spread in spreads { - self.find_undef_vars(&Scope::Fragment(spread), defined, unused, visited); + self.find_undef_vars(&Scope::Fragment(spread), defined, undef, visited); } } } @@ -49,16 +49,16 @@ impl<'a> NoUndefinedVariables<'a> { impl<'a> Visitor<'a> for NoUndefinedVariables<'a> { fn exit_document(&mut self, ctx: &mut VisitorContext<'a>, _doc: &'a ExecutableDocument) { for (op_name, &(ref def_pos, ref def_vars)) in &self.defined_variables { - let mut unused = Vec::new(); + let mut undef = Vec::new(); let mut visited = HashSet::new(); self.find_undef_vars( &Scope::Operation(*op_name), def_vars, - &mut unused, + &mut undef, &mut visited, ); - for (var, pos) in unused { + for (var, pos) in undef { if let Some(op_name) = op_name { ctx.report_error( vec![*def_pos, pos], @@ -115,7 +115,7 @@ impl<'a> Visitor<'a> for NoUndefinedVariables<'a> { ) { if let Some(ref scope) = self.current_scope { self.used_variables - .entry(scope.clone()) + .entry(*scope) .or_insert_with(HashMap::new) .extend( referenced_variables(&value.node) @@ -132,7 +132,7 @@ impl<'a> Visitor<'a> for NoUndefinedVariables<'a> { ) { if let Some(ref scope) = self.current_scope { self.spreads - .entry(scope.clone()) + .entry(*scope) .or_insert_with(Vec::new) .push(&fragment_spread.node.fragment_name.node); } diff --git a/src/validation/rules/no_unused_fragments.rs b/src/validation/rules/no_unused_fragments.rs index da3dd117..5e432fd2 100644 --- a/src/validation/rules/no_unused_fragments.rs +++ b/src/validation/rules/no_unused_fragments.rs @@ -80,7 +80,7 @@ impl<'a> Visitor<'a> for NoUnusedFragments<'a> { ) { if let Some(ref scope) = self.current_scope { self.spreads - .entry(scope.clone()) + .entry(*scope) .or_insert_with(Vec::new) .push(&fragment_spread.node.fragment_name.node); } diff --git a/src/validation/rules/no_unused_variables.rs b/src/validation/rules/no_unused_variables.rs index 10019b73..75f925b5 100644 --- a/src/validation/rules/no_unused_variables.rs +++ b/src/validation/rules/no_unused_variables.rs @@ -28,7 +28,7 @@ impl<'a> NoUnusedVariables<'a> { return; } - visited.insert(from.clone()); + visited.insert(*from); if let Some(used_vars) = self.used_variables.get(from) { for var in used_vars { @@ -114,7 +114,7 @@ impl<'a> Visitor<'a> for NoUnusedVariables<'a> { ) { if let Some(ref scope) = self.current_scope { self.used_variables - .entry(scope.clone()) + .entry(*scope) .or_insert_with(Vec::new) .append(&mut referenced_variables(&value.node)); } @@ -127,7 +127,7 @@ impl<'a> Visitor<'a> for NoUnusedVariables<'a> { ) { if let Some(ref scope) = self.current_scope { self.spreads - .entry(scope.clone()) + .entry(*scope) .or_insert_with(Vec::new) .push(&fragment_spread.node.fragment_name.node); } diff --git a/src/validation/rules/variables_in_allowed_position.rs b/src/validation/rules/variables_in_allowed_position.rs index 19945dde..e8a837ee 100644 --- a/src/validation/rules/variables_in_allowed_position.rs +++ b/src/validation/rules/variables_in_allowed_position.rs @@ -29,7 +29,7 @@ impl<'a> VariableInAllowedPosition<'a> { return; } - visited.insert(from.clone()); + visited.insert(*from); if let Some(usages) = self.variable_usages.get(from) { for (var_name, usage_pos, var_type) in usages { @@ -95,7 +95,7 @@ impl<'a> Visitor<'a> for VariableInAllowedPosition<'a> { ) { if let Some(ref scope) = self.current_scope { self.variable_defs - .entry(scope.clone()) + .entry(*scope) .or_insert_with(Vec::new) .push(variable_definition); } @@ -108,7 +108,7 @@ impl<'a> Visitor<'a> for VariableInAllowedPosition<'a> { ) { if let Some(ref scope) = self.current_scope { self.spreads - .entry(scope.clone()) + .entry(*scope) .or_insert_with(HashSet::new) .insert(&fragment_spread.node.fragment_name.node); } @@ -125,7 +125,7 @@ impl<'a> Visitor<'a> for VariableInAllowedPosition<'a> { if let Some(expected_type) = expected_type { if let Some(scope) = &self.current_scope { self.variable_usages - .entry(scope.clone()) + .entry(*scope) .or_insert_with(Vec::new) .push((name, pos, *expected_type)); } diff --git a/src/validation/utils.rs b/src/validation/utils.rs index 1a207f3d..ac709bfe 100644 --- a/src/validation/utils.rs +++ b/src/validation/utils.rs @@ -4,7 +4,7 @@ use crate::context::QueryPathNode; use crate::{registry, QueryPathSegment}; use async_graphql_value::{ConstValue, Value}; -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Scope<'a> { Operation(Option<&'a str>), Fragment(&'a str), diff --git a/tests/list.rs b/tests/list.rs index a2dee968..fd4795f2 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -2,6 +2,7 @@ use async_graphql::*; use std::cmp::Ordering; use std::collections::{BTreeSet, HashSet, LinkedList, VecDeque}; +//noinspection ALL #[async_std::test] pub async fn test_list_type() { #[derive(InputObject)] @@ -87,17 +88,15 @@ pub async fn test_list_type() { let mut res = schema.execute(&query).await.data; if let Value::Object(obj) = &mut res { - if let Some(value_hash_set) = obj.get_mut("valueHashSet") { - if let Value::List(array) = value_hash_set { - array.sort_by(|a, b| { - if let (Value::Number(a), Value::Number(b)) = (a, b) { - if let (Some(a), Some(b)) = (a.as_i64(), b.as_i64()) { - return a.cmp(&b); - } + if let Some(Value::List(array)) = obj.get_mut("valueHashSet") { + array.sort_by(|a, b| { + if let (Value::Number(a), Value::Number(b)) = (a, b) { + if let (Some(a), Some(b)) = (a.as_i64(), b.as_i64()) { + return a.cmp(&b); } - Ordering::Less - }); - } + } + Ordering::Less + }); } }