Skip to content

Commit f7e0ffa

Browse files
authored
Merge pull request #34 from Mrmaxmeier/fix-clippy-warnings
Fix a bunch of clippy warnings
2 parents 3035eb8 + 5d7634c commit f7e0ffa

37 files changed

+213
-223
lines changed

src/ast.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<'a> Type<'a> {
168168
/// Only applies to named types; lists will return `None`.
169169
pub fn name(&self) -> Option<&str> {
170170
match *self {
171-
Type::Named(ref n) | Type::NonNullNamed(ref n) => Some(n),
171+
Type::Named(n) | Type::NonNullNamed(n) => Some(n),
172172
_ => None
173173
}
174174
}
@@ -178,7 +178,7 @@ impl<'a> Type<'a> {
178178
/// All type literals contain exactly one named type.
179179
pub fn innermost_name(&self) -> &str {
180180
match *self {
181-
Type::Named(ref n) | Type::NonNullNamed(ref n) => n,
181+
Type::Named(n) | Type::NonNullNamed(n) => n,
182182
Type::List(ref l) | Type::NonNullList(ref l) => l.innermost_name(),
183183
}
184184
}
@@ -195,8 +195,8 @@ impl<'a> Type<'a> {
195195
impl<'a> fmt::Display for Type<'a> {
196196
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
197197
match *self {
198-
Type::Named(ref n) => write!(f, "{}", n),
199-
Type::NonNullNamed(ref n) => write!(f, "{}!", n),
198+
Type::Named(n) => write!(f, "{}", n),
199+
Type::NonNullNamed(n) => write!(f, "{}!", n),
200200
Type::List(ref t) => write!(f, "[{}]", t),
201201
Type::NonNullList(ref t) => write!(f, "[{}]!", t),
202202
}
@@ -237,7 +237,7 @@ impl InputValue {
237237
/// not contain any location information. Can be used from `ToInputValue`
238238
/// implementations, where no source code position information is available.
239239
pub fn list(l: Vec<InputValue>) -> InputValue {
240-
InputValue::List(l.into_iter().map(|i| Spanning::unlocated(i)).collect())
240+
InputValue::List(l.into_iter().map(Spanning::unlocated).collect())
241241
}
242242

243243
/// Construct a located list.
@@ -371,7 +371,7 @@ impl InputValue {
371371
(&Variable(ref s1), &Variable(ref s2)) => s1 == s2,
372372
(&Boolean(b1), &Boolean(b2)) => b1 == b2,
373373
(&List(ref l1), &List(ref l2)) =>
374-
l1.iter().zip(l2.iter()).all(|(ref v1, ref v2)| v1.item.unlocated_eq(&v2.item)),
374+
l1.iter().zip(l2.iter()).all(|(v1, v2)| v1.item.unlocated_eq(&v2.item)),
375375
(&Object(ref o1), &Object(ref o2)) =>
376376
o1.len() == o2.len()
377377
&& o1.iter()

src/executor.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'a, T: GraphQLType, C> IntoResolvable<'a, T, C> for Option<(&'a T::Context,
9696

9797
impl<'a, T: GraphQLType, C> IntoResolvable<'a, T, C> for FieldResult<(&'a T::Context, T)> {
9898
fn into(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, T)>> {
99-
self.map(|v| Some(v))
99+
self.map(Some)
100100
}
101101
}
102102

@@ -148,7 +148,7 @@ impl<'a, CtxT> Executor<'a, CtxT> {
148148
) -> ExecutionResult
149149
where NewCtxT: FromContext<CtxT>,
150150
{
151-
self.replaced_context(<NewCtxT as FromContext<CtxT>>::from(&self.context))
151+
self.replaced_context(<NewCtxT as FromContext<CtxT>>::from(self.context))
152152
.resolve(value)
153153
}
154154

@@ -179,7 +179,7 @@ impl<'a, CtxT> Executor<'a, CtxT> {
179179
Executor {
180180
fragments: self.fragments,
181181
variables: self.variables,
182-
current_selection_set: self.current_selection_set.clone(),
182+
current_selection_set: self.current_selection_set,
183183
schema: self.schema,
184184
context: ctx,
185185
errors: self.errors,
@@ -252,9 +252,9 @@ impl<'a> FieldPath<'a> {
252252
fn construct_path(&self, acc: &mut Vec<String>) {
253253
match *self {
254254
FieldPath::Root(_) => (),
255-
FieldPath::Field(ref name, _, ref parent) => {
255+
FieldPath::Field(name, _, parent) => {
256256
parent.construct_path(acc);
257-
acc.push((*name).to_owned());
257+
acc.push(name.to_owned());
258258
}
259259
}
260260
}
@@ -347,9 +347,7 @@ pub fn execute_validated_query<'a, QueryT, MutationT, CtxT>(
347347
all_vars = variables.clone();
348348

349349
for (name, value) in defaults {
350-
if !all_vars.contains_key(&name) {
351-
all_vars.insert(name, value);
352-
}
350+
all_vars.entry(name).or_insert(value);
353351
}
354352

355353
final_vars = &all_vars;

src/integrations/iron_handlers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'a, CtxFactory, Query, Mutation, CtxT>
8787
let mut query = None;
8888
let mut variables = Variables::new();
8989

90-
for (k, v) in json_obj.into_iter() {
90+
for (k, v) in json_obj {
9191
if k == "query" {
9292
query = v.as_string().map(|s| s.to_owned());
9393
}

src/macros/enums.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ macro_rules! graphql_enum {
8484
}
8585

8686
fn resolve(&self, _: Option<&[$crate::Selection]>, _: &$crate::Executor<Self::Context>) -> $crate::Value {
87-
match self {
87+
match *self {
8888
$(
89-
&graphql_enum!(@as_pattern, $eval) =>
89+
graphql_enum!(@as_pattern, $eval) =>
9090
$crate::Value::string(graphql_enum!(@as_expr, $ename)) ),*
9191
}
9292
}
@@ -105,9 +105,9 @@ macro_rules! graphql_enum {
105105

106106
impl $crate::ToInputValue for $name {
107107
fn to(&self) -> $crate::InputValue {
108-
match self {
108+
match *self {
109109
$(
110-
&graphql_enum!(@as_pattern, $eval) =>
110+
graphql_enum!(@as_pattern, $eval) =>
111111
$crate::InputValue::string(graphql_enum!(@as_expr, $ename)) ),*
112112
}
113113
}

src/macros/field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ macro_rules! __graphql__build_field_matches {
6969
) => {
7070
$(
7171
if $fieldvar == &$crate::to_camel_case(stringify!($name)) {
72-
let result: $t = (|| {
72+
let result: $t = (||{
7373
__graphql__args!(
7474
@assign_arg_vars,
7575
$argsvar, $executorvar, $($args)*

src/macros/interface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ macro_rules! graphql_interface {
191191
let $ctxtvar = &$ctxtarg;
192192

193193
$(
194-
if let Some(_) = $resolver as Option<$srctype> {
194+
if ($resolver as Option<$srctype>).is_some() {
195195
return (<$srctype as $crate::GraphQLType>::name()).unwrap().to_owned();
196196
}
197197
)*
@@ -208,7 +208,7 @@ macro_rules! graphql_interface {
208208
let $ctxtvar = &$execarg.context();
209209

210210
$(
211-
if $typenamearg == (<$srctype as $crate::GraphQLType>::name()).unwrap().to_owned() {
211+
if $typenamearg == (<$srctype as $crate::GraphQLType>::name()).unwrap() {
212212
return $execarg.resolve(&$resolver);
213213
}
214214
)*

src/parser/lexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ impl<'a> Iterator for Lexer<'a> {
469469
impl<'a> fmt::Display for Token<'a> {
470470
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
471471
match *self {
472-
Token::Name(ref name) => write!(f, "{}", name),
472+
Token::Name(name) => write!(f, "{}", name),
473473
Token::Int(i) => write!(f, "{}", i),
474474
Token::Float(v) => write!(f, "{}", v),
475475
Token::String(ref s) => write!(f, "\"{}\"", s.replace('\\', "\\\\").replace('"', "\\\"")),

src/parser/value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn parse_list_literal<'a>(parser: &mut Parser<'a>, is_const: bool) -> ParseResul
3636
&Token::BracketOpen,
3737
|p| parse_value_literal(p, is_const),
3838
&Token::BracketClose
39-
)).map(|items| InputValue::parsed_list(items)))
39+
)).map(InputValue::parsed_list))
4040
}
4141

4242
fn parse_object_literal<'a>(parser: &mut Parser<'a>, is_const: bool) -> ParseResult<'a, InputValue> {

src/schema/meta.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ impl<'a> MetaType<'a> {
174174
/// Lists, non-null wrappers, and placeholders don't have names.
175175
pub fn name(&self) -> Option<&str> {
176176
match *self {
177-
MetaType::Scalar(ScalarMeta { ref name, .. }) |
178-
MetaType::Object(ObjectMeta { ref name, .. }) |
179-
MetaType::Enum(EnumMeta { ref name, .. }) |
180-
MetaType::Interface(InterfaceMeta { ref name, .. }) |
181-
MetaType::Union(UnionMeta { ref name, .. }) |
182-
MetaType::InputObject(InputObjectMeta { ref name, .. }) =>
177+
MetaType::Scalar(ScalarMeta { name, .. }) |
178+
MetaType::Object(ObjectMeta { name, .. }) |
179+
MetaType::Enum(EnumMeta { name, .. }) |
180+
MetaType::Interface(InterfaceMeta { name, .. }) |
181+
MetaType::Union(UnionMeta { name, .. }) |
182+
MetaType::InputObject(InputObjectMeta { name, .. }) =>
183183
Some(name),
184184
_ => None,
185185
}
@@ -226,7 +226,7 @@ impl<'a> MetaType<'a> {
226226
match *self {
227227
MetaType::Object(ObjectMeta { ref fields, .. }) |
228228
MetaType::Interface(InterfaceMeta { ref fields, .. }) =>
229-
fields.iter().filter(|f| f.name == name).next(),
229+
fields.iter().find(|f| f.name == name),
230230
_ => None,
231231
}
232232
}
@@ -237,26 +237,26 @@ impl<'a> MetaType<'a> {
237237
pub fn input_field_by_name(&self, name: &str) -> Option<&Argument> {
238238
match *self {
239239
MetaType::InputObject(InputObjectMeta { ref input_fields, .. }) =>
240-
input_fields.iter().filter(|f| f.name == name).next(),
240+
input_fields.iter().find(|f| f.name == name),
241241
_ => None,
242242
}
243243
}
244244

245245
/// Construct a `Type` literal instance based on the metadata
246246
pub fn as_type(&self) -> Type<'a> {
247247
match *self {
248-
MetaType::Scalar(ScalarMeta { ref name, .. }) |
249-
MetaType::Object(ObjectMeta { ref name, .. }) |
250-
MetaType::Enum(EnumMeta { ref name, .. }) |
251-
MetaType::Interface(InterfaceMeta { ref name, .. }) |
252-
MetaType::Union(UnionMeta { ref name, .. }) |
253-
MetaType::InputObject(InputObjectMeta { ref name, .. }) =>
248+
MetaType::Scalar(ScalarMeta { name, .. }) |
249+
MetaType::Object(ObjectMeta { name, .. }) |
250+
MetaType::Enum(EnumMeta { name, .. }) |
251+
MetaType::Interface(InterfaceMeta { name, .. }) |
252+
MetaType::Union(UnionMeta { name, .. }) |
253+
MetaType::InputObject(InputObjectMeta { name, .. }) =>
254254
Type::NonNullNamed(name),
255255
MetaType::List(ListMeta { ref of_type }) =>
256256
Type::NonNullList(Box::new(of_type.clone())),
257257
MetaType::Nullable(NullableMeta { ref of_type }) =>
258258
match *of_type {
259-
Type::NonNullNamed(ref inner) => Type::Named(inner.to_owned()),
259+
Type::NonNullNamed(inner) => Type::Named(inner),
260260
Type::NonNullList(ref inner) => Type::List(inner.clone()),
261261
ref t => t.clone(),
262262
},

src/schema/model.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'a> SchemaType<'a> {
9797
];
9898

9999
if let Some(root_type) = registry.types.get_mut(&query_type_name) {
100-
if let &mut MetaType::Object(ObjectMeta { ref mut fields, .. }) = root_type {
100+
if let MetaType::Object(ObjectMeta { ref mut fields, .. }) = *root_type {
101101
fields.append(&mut meta_fields);
102102
}
103103
else {
@@ -171,13 +171,13 @@ impl<'a> SchemaType<'a> {
171171

172172
pub fn make_type(&self, t: &Type) -> TypeType {
173173
match *t {
174-
Type::NonNullNamed(ref n) =>
174+
Type::NonNullNamed(n) =>
175175
TypeType::NonNull(Box::new(
176176
self.type_by_name(n).expect("Type not found in schema"))),
177177
Type::NonNullList(ref inner) =>
178178
TypeType::NonNull(Box::new(
179179
TypeType::List(Box::new(self.make_type(inner))))),
180-
Type::Named(ref n) => self.type_by_name(n).expect("Type not found in schema"),
180+
Type::Named(n) => self.type_by_name(n).expect("Type not found in schema"),
181181
Type::List(ref inner) =>
182182
TypeType::List(Box::new(self.make_type(inner))),
183183
}
@@ -211,7 +211,7 @@ impl<'a> SchemaType<'a> {
211211
.iter()
212212
.flat_map(|t| self.concrete_type_by_name(t))
213213
.collect(),
214-
MetaType::Interface(InterfaceMeta { ref name, .. }) =>
214+
MetaType::Interface(InterfaceMeta { name, .. }) =>
215215
self.concrete_type_list()
216216
.into_iter()
217217
.filter(|t| match **t {
@@ -238,9 +238,9 @@ impl<'a> SchemaType<'a> {
238238
}
239239

240240
match (super_type, sub_type) {
241-
(&NonNullNamed(ref super_name), &NonNullNamed(ref sub_name)) |
242-
(&Named(ref super_name), &Named(ref sub_name)) |
243-
(&Named(ref super_name), &NonNullNamed(ref sub_name)) =>
241+
(&NonNullNamed(super_name), &NonNullNamed(sub_name)) |
242+
(&Named(super_name), &Named(sub_name)) |
243+
(&Named(super_name), &NonNullNamed(sub_name)) =>
244244
self.is_named_subtype(sub_name, super_name),
245245
(&NonNullList(ref super_inner), &NonNullList(ref sub_inner)) |
246246
(&List(ref super_inner), &List(ref sub_inner)) |
@@ -332,7 +332,7 @@ impl fmt::Display for DirectiveLocation {
332332
impl<'a> fmt::Display for TypeType<'a> {
333333
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
334334
match *self {
335-
TypeType::Concrete(ref t) => f.write_str(&t.name().unwrap()),
335+
TypeType::Concrete(t) => f.write_str(t.name().unwrap()),
336336
TypeType::List(ref i) => write!(f, "[{}]", i),
337337
TypeType::NonNull(ref i) => write!(f, "{}!", i),
338338
}

0 commit comments

Comments
 (0)