Clippy clean
This commit is contained in:
parent
68b5ed680f
commit
144ddb752c
|
@ -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<Scope<'a>>,
|
||||
) {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user