@@ -16,6 +16,7 @@ use super::ValidationRule;
1616/// Variable usages must be compatible with the arguments they are passed to.
1717///
1818/// See https://spec.graphql.org/draft/#sec-All-Variable-Usages-are-Allowed
19+ #[ derive( Default ) ]
1920pub struct VariablesInAllowedPosition < ' a > {
2021 spreads : HashMap < Scope < ' a > , HashSet < & ' a str > > ,
2122 variable_usages : HashMap < Scope < ' a > , Vec < ( & ' a str , & ' a Type ) > > ,
@@ -49,8 +50,7 @@ impl<'a> VariablesInAllowedPosition<'a> {
4950
5051 if let Some ( usages) = self . variable_usages . get ( from) {
5152 for ( var_name, var_type) in usages {
52- if let Some ( ref var_def) = var_defs. iter ( ) . find ( |var_def| var_def. name == * var_name)
53- {
53+ if let Some ( var_def) = var_defs. iter ( ) . find ( |var_def| var_def. name == * var_name) {
5454 let expected_type = match ( & var_def. default_value , & var_def. var_type ) {
5555 ( Some ( _) , Type :: ListType ( inner) ) => Type :: NonNullType ( inner. clone ( ) ) ,
5656 ( Some ( default_value) , Type :: NamedType ( _) ) => {
@@ -143,7 +143,7 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for VariablesInAllowedPosi
143143 if let Some ( scope) = & self . current_scope {
144144 self . spreads
145145 . entry ( scope. clone ( ) )
146- . or_insert_with ( HashSet :: new )
146+ . or_default ( )
147147 . insert ( & fragment_spread. fragment_name ) ;
148148 }
149149 }
@@ -158,7 +158,7 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for VariablesInAllowedPosi
158158 self . variable_defs
159159 . entry ( scope. clone ( ) )
160160 . or_default ( )
161- . push ( & variable_definition) ;
161+ . push ( variable_definition) ;
162162 }
163163 }
164164
@@ -168,13 +168,13 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for VariablesInAllowedPosi
168168 _: & mut ValidationErrorContext ,
169169 variable_name : & ' a str ,
170170 ) {
171- if let ( & Some ( ref scope) , Some ( input_type) ) = (
171+ if let ( Some ( scope) , Some ( input_type) ) = (
172172 & self . current_scope ,
173173 visitor_context. current_input_type_literal ( ) ,
174174 ) {
175175 self . variable_usages
176176 . entry ( scope. clone ( ) )
177- . or_insert_with ( Vec :: new )
177+ . or_default ( )
178178 . push ( ( variable_name, input_type) ) ;
179179 }
180180 }
@@ -185,14 +185,14 @@ impl<'v> ValidationRule for VariablesInAllowedPosition<'v> {
185185 "VariablesInAllowedPosition"
186186 }
187187
188- fn validate < ' a > (
188+ fn validate (
189189 & self ,
190- ctx : & ' a mut OperationVisitorContext ,
190+ ctx : & mut OperationVisitorContext ,
191191 error_collector : & mut ValidationErrorContext ,
192192 ) {
193193 visit_document (
194194 & mut VariablesInAllowedPosition :: new ( ) ,
195- & ctx. operation ,
195+ ctx. operation ,
196196 ctx,
197197 error_collector,
198198 ) ;
0 commit comments