Skip to content

Commit 95f114e

Browse files
committed
getting there
1 parent a59fb34 commit 95f114e

File tree

6 files changed

+35
-54
lines changed

6 files changed

+35
-54
lines changed

src/ast/ext.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -621,31 +621,19 @@ impl TypeDefinitionExtension for schema::TypeDefinition {
621621
}
622622

623623
fn is_object_type(&self) -> bool {
624-
match self {
625-
schema::TypeDefinition::Object(_o) => true,
626-
_ => false,
627-
}
624+
matches!(self, schema::TypeDefinition::Object(_o))
628625
}
629626

630627
fn is_union_type(&self) -> bool {
631-
match self {
632-
schema::TypeDefinition::Union(_o) => true,
633-
_ => false,
634-
}
628+
matches!(self, schema::TypeDefinition::Union(_o))
635629
}
636630

637631
fn is_enum_type(&self) -> bool {
638-
match self {
639-
schema::TypeDefinition::Enum(_o) => true,
640-
_ => false,
641-
}
632+
matches!(self, schema::TypeDefinition::Enum(_o))
642633
}
643634

644635
fn is_scalar_type(&self) -> bool {
645-
match self {
646-
schema::TypeDefinition::Scalar(_o) => true,
647-
_ => false,
648-
}
636+
matches!(self, schema::TypeDefinition::Scalar(_o))
649637
}
650638
}
651639

src/ast/operation_transformer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ pub trait OperationTransformer<'a, T: Text<'a> + Clone> {
370370

371371
fn transform_directives(
372372
&mut self,
373-
directives: &Vec<Directive<'a, T>>,
373+
directives: &[Directive<'a, T>],
374374
) -> TransformedValue<Vec<Directive<'a, T>>> {
375375
self.transform_list(directives, Self::transform_directive)
376376
}
@@ -452,7 +452,7 @@ pub trait OperationTransformer<'a, T: Text<'a> + Clone> {
452452

453453
fn default_transform_variable_definitions(
454454
&mut self,
455-
variable_definitions: &Vec<VariableDefinition<'a, T>>,
455+
variable_definitions: &[VariableDefinition<'a, T>],
456456
) -> TransformedValue<Vec<VariableDefinition<'a, T>>> {
457457
self.transform_list(
458458
variable_definitions,

src/validation/rules/known_fragment_names.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for KnownFragmentNames {
3030
user_context: &mut ValidationErrorContext,
3131
fragment_spread: &FragmentSpread,
3232
) {
33-
if visitor_context
33+
if !visitor_context
3434
.known_fragments
35-
.get(fragment_spread.fragment_name.as_str()).is_none() { user_context.report_error(ValidationError {
36-
error_code: self.error_code(),
37-
locations: vec![fragment_spread.position],
38-
message: format!("Unknown fragment \"{}\".", fragment_spread.fragment_name),
39-
}) }
35+
.contains_key(fragment_spread.fragment_name.as_str())
36+
{
37+
user_context.report_error(ValidationError {
38+
error_code: self.error_code(),
39+
locations: vec![fragment_spread.position],
40+
message: format!("Unknown fragment \"{}\".", fragment_spread.fragment_name),
41+
})
42+
}
4043
}
4144
}
4245

src/validation/rules/overlapping_fields_can_be_merged.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,9 @@ impl<'a> PairSet<'a> {
194194
}
195195

196196
pub fn insert(&mut self, a: &'a str, b: &'a str, mutex: bool) {
197-
self.data
198-
.entry(a)
199-
.or_default()
200-
.insert(b, mutex);
201-
202-
self.data
203-
.entry(b)
204-
.or_default()
205-
.insert(a, mutex);
197+
self.data.entry(a).or_default().insert(b, mutex);
198+
199+
self.data.entry(b).or_default().insert(a, mutex);
206200
}
207201
}
208202

@@ -303,11 +297,7 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> {
303297
}
304298
}
305299

306-
fn is_same_arguments(
307-
&self,
308-
f1_args: &Vec<(String, Value)>,
309-
f2_args: &Vec<(String, Value)>,
310-
) -> bool {
300+
fn is_same_arguments(&self, f1_args: &[(String, Value)], f2_args: &[(String, Value)]) -> bool {
311301
if f1_args.len() != f2_args.len() {
312302
return false;
313303
}
@@ -324,10 +314,10 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> {
324314
// Two types conflict if both types could not apply to a value simultaneously.
325315
// Composite types are ignored as their individual field types will be compared
326316
// later recursively. However List and Non-Null types must match.
327-
fn is_type_conflict(&self, schema: &SchemaDocument, t1: &Type, t2: &Type) -> bool {
317+
fn is_type_conflict(schema: &SchemaDocument, t1: &Type, t2: &Type) -> bool {
328318
if let Type::ListType(t1) = t1 {
329319
if let Type::ListType(t2) = t2 {
330-
return self.is_type_conflict(schema, t1, t2);
320+
return Self::is_type_conflict(schema, t1, t2);
331321
} else {
332322
return true;
333323
}
@@ -339,7 +329,7 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> {
339329

340330
if let Type::NonNullType(t1) = t1 {
341331
if let Type::NonNullType(t2) = t2 {
342-
return self.is_type_conflict(schema, t1, t2);
332+
return Self::is_type_conflict(schema, t1, t2);
343333
} else {
344334
return true;
345335
}
@@ -422,7 +412,7 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> {
422412
let t2 = field2_def.as_ref().map(|def| &def.field_type);
423413

424414
if let (Some(t1), Some(t2)) = (t1, t2) {
425-
if self.is_type_conflict(schema, t1, t2) {
415+
if Self::is_type_conflict(schema, t1, t2) {
426416
return Some(Conflict(
427417
ConflictReason(
428418
out_field_name.to_owned(),
@@ -464,7 +454,7 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> {
464454

465455
fn subfield_conflicts(
466456
&self,
467-
conflicts: &Vec<Conflict>,
457+
conflicts: &[Conflict],
468458
out_field_name: &str,
469459
f1_pos: Pos,
470460
f2_pos: Pos,
@@ -492,6 +482,7 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> {
492482
// Find all conflicts found between two selection sets, including those found
493483
// via spreading in fragments. Called when determining if conflicts exist
494484
// between the sub-fields of two overlapping fields.
485+
#[allow(clippy::too_many_arguments)]
495486
fn find_conflicts_between_sub_selection_sets(
496487
&mut self,
497488
schema: &'a SchemaDocument,
@@ -758,7 +749,7 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> {
758749
let mut ast_and_defs = OrderedMap::new();
759750
let mut fragment_names = Vec::new();
760751

761-
self.collect_fields_and_fragment_names(
752+
Self::collect_fields_and_fragment_names(
762753
schema,
763754
parent_type,
764755
selection_set,
@@ -770,7 +761,6 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> {
770761
}
771762

772763
fn collect_fields_and_fragment_names(
773-
&self,
774764
schema: &'a SchemaDocument,
775765
parent_type: Option<&'a TypeDefinition>,
776766
selection_set: &'a SelectionSet,
@@ -795,7 +785,8 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> {
795785
}
796786
Selection::FragmentSpread(fragment_spread) => {
797787
if !fragment_names
798-
.iter().any(|n| (*n).eq(&fragment_spread.fragment_name))
788+
.iter()
789+
.any(|n| (*n).eq(&fragment_spread.fragment_name))
799790
{
800791
fragment_names.push(&fragment_spread.fragment_name);
801792
}
@@ -811,7 +802,7 @@ impl<'a> OverlappingFieldsCanBeMerged<'a> {
811802
})
812803
.or(parent_type);
813804

814-
self.collect_fields_and_fragment_names(
805+
Self::collect_fields_and_fragment_names(
815806
schema,
816807
fragment_type,
817808
&inline_fragment.selection_set,

src/validation/rules/provided_required_arguments.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,17 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for ProvidedRequiredArgume
7373
}
7474
}
7575

76-
fn validate_arguments<'a>(
77-
arguments_used: &Vec<(String, Value)>,
78-
arguments_defined: &Vec<InputValue>,
76+
fn validate_arguments(
77+
arguments_used: &[(String, Value)],
78+
arguments_defined: &[InputValue],
7979
) -> Vec<InputValue> {
8080
arguments_defined
8181
.iter()
8282
.filter_map(|field_arg_def| {
8383
if field_arg_def.is_required()
8484
&& !arguments_used
85-
.iter().any(|(name, _value)| name.eq(&field_arg_def.name))
85+
.iter()
86+
.any(|(name, _value)| name.eq(&field_arg_def.name))
8687
{
8788
Some(field_arg_def.clone())
8889
} else {

src/validation/test_utils.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,11 @@ pub fn create_plan_from_rule(rule: Box<dyn ValidationRule>) -> ValidationPlan {
233233
let mut rules = Vec::new();
234234
rules.push(rule);
235235

236-
237-
238236
ValidationPlan { rules }
239237
}
240238

241239
#[cfg(test)]
242-
pub fn get_messages(validation_errors: &Vec<ValidationError>) -> Vec<&String> {
240+
pub fn get_messages(validation_errors: &[ValidationError]) -> Vec<&String> {
243241
validation_errors
244242
.iter()
245243
.map(|m| &m.message)

0 commit comments

Comments
 (0)