From b9257ef7d44bb677c916b6636e2f317569b8728f Mon Sep 17 00:00:00 2001 From: nickelc Date: Sun, 12 Sep 2021 19:38:41 +0200 Subject: [PATCH] Fix Clippy warnings (#980) --- integration_tests/async_await/src/main.rs | 5 +---- juniper/src/executor/look_ahead.rs | 6 +++--- juniper/src/executor/mod.rs | 2 +- juniper/src/http/mod.rs | 2 +- juniper/src/lib.rs | 2 +- juniper/src/parser/utils.rs | 1 + juniper/src/schema/meta.rs | 2 +- juniper/src/schema/translate/graphql_parser.rs | 4 ++-- juniper/src/tests/fixtures/starwars/schema.rs | 1 + juniper/src/types/async_await.rs | 6 +++--- juniper/src/types/base.rs | 4 ++-- juniper/src/types/subscriptions.rs | 8 ++++---- juniper/src/validation/input_value.rs | 2 +- juniper/src/validation/rules/known_argument_names.rs | 2 +- juniper/src/validation/rules/known_directives.rs | 5 ++--- .../validation/rules/overlapping_fields_can_be_merged.rs | 2 +- .../src/validation/rules/variables_in_allowed_position.rs | 1 + juniper_actix/src/lib.rs | 6 +++--- juniper_codegen/src/common/field/arg.rs | 1 - juniper_codegen/src/util/mod.rs | 6 +++--- juniper_warp/src/lib.rs | 6 +++--- 21 files changed, 36 insertions(+), 38 deletions(-) diff --git a/integration_tests/async_await/src/main.rs b/integration_tests/async_await/src/main.rs index cf58f90f..ce185ba8 100644 --- a/integration_tests/async_await/src/main.rs +++ b/integration_tests/async_await/src/main.rs @@ -1,7 +1,4 @@ -use juniper::{ - graphql_object, graphql_value, EmptyMutation, EmptySubscription, GraphQLEnum, GraphQLError, - RootNode, Value, -}; +use juniper::{graphql_object, GraphQLEnum}; #[derive(GraphQLEnum)] enum UserKind { diff --git a/juniper/src/executor/look_ahead.rs b/juniper/src/executor/look_ahead.rs index b4e65952..f7f020b3 100644 --- a/juniper/src/executor/look_ahead.rs +++ b/juniper/src/executor/look_ahead.rs @@ -87,7 +87,7 @@ where /// The argument's name pub fn name(&'a self) -> &str { - &self.name + self.name } /// The value of the argument @@ -289,7 +289,7 @@ where fragments, ); assert!(s.is_none()); - if let Some(ref c) = inline.item.type_condition.as_ref().map(|t| t.item) { + if let Some(c) = inline.item.type_condition.as_ref().map(|t| t.item) { if let Some(p) = parent.children.last_mut() { p.applies_for = Applies::OnlyType(c); } @@ -308,7 +308,7 @@ where .children .iter() .filter_map(|c| match c.applies_for { - Applies::OnlyType(ref t) if *t == type_name => { + Applies::OnlyType(t) if t == type_name => { Some(c.inner.for_explicit_type(type_name)) } Applies::All => Some(c.inner.for_explicit_type(type_name)), diff --git a/juniper/src/executor/mod.rs b/juniper/src/executor/mod.rs index 5e7e3182..c27cd843 100644 --- a/juniper/src/executor/mod.rs +++ b/juniper/src/executor/mod.rs @@ -689,7 +689,7 @@ where } }); if let Some(p) = found_field { - LookAheadSelection::build_from_selection(&p, self.variables, self.fragments) + LookAheadSelection::build_from_selection(p, self.variables, self.fragments) } else { None } diff --git a/juniper/src/http/mod.rs b/juniper/src/http/mod.rs index 8ff13c59..72d79603 100644 --- a/juniper/src/http/mod.rs +++ b/juniper/src/http/mod.rs @@ -47,7 +47,7 @@ where { // TODO: Remove in 0.17 `juniper` version. /// Returns the `operation_name` associated with this request. - #[deprecated(since = "0.16", note = "Use the direct field access instead.")] + #[deprecated(since = "0.16.0", note = "Use the direct field access instead.")] pub fn operation_name(&self) -> Option<&str> { self.operation_name.as_deref() } diff --git a/juniper/src/lib.rs b/juniper/src/lib.rs index 8c361bfe..aa4fcbcb 100644 --- a/juniper/src/lib.rs +++ b/juniper/src/lib.rs @@ -335,7 +335,7 @@ where let operation = get_operation(&document, operation_name)?; { - let errors = validate_input_values(&variables, operation, &root_node.schema); + let errors = validate_input_values(variables, operation, &root_node.schema); if !errors.is_empty() { return Err(GraphQLError::ValidationError(errors)); diff --git a/juniper/src/parser/utils.rs b/juniper/src/parser/utils.rs index 5ea12817..771adfc4 100644 --- a/juniper/src/parser/utils.rs +++ b/juniper/src/parser/utils.rs @@ -59,6 +59,7 @@ impl Spanning { } #[doc(hidden)] + #[allow(clippy::self_named_constructors)] pub fn spanning(v: Vec>) -> Option>>> { if let (Some(start), Some(end)) = (v.first().map(|s| s.start), v.last().map(|s| s.end)) { Some(Spanning { diff --git a/juniper/src/schema/meta.rs b/juniper/src/schema/meta.rs index f5ac2c0f..6566df91 100644 --- a/juniper/src/schema/meta.rs +++ b/juniper/src/schema/meta.rs @@ -399,7 +399,7 @@ impl<'a, S> MetaType<'a, S> { .iter() .filter_map(|n| schema.concrete_type_by_name(n)) .filter_map(|t| t.fields(schema)) - .flat_map(|f| f) + .flatten() .collect(), ), _ => None, diff --git a/juniper/src/schema/translate/graphql_parser.rs b/juniper/src/schema/translate/graphql_parser.rs index 3c8ac75f..ded21fd7 100644 --- a/juniper/src/schema/translate/graphql_parser.rs +++ b/juniper/src/schema/translate/graphql_parser.rs @@ -256,7 +256,7 @@ impl GraphQLParserTranslator { .map(|a| { a.iter() .filter(|x| !x.is_builtin()) - .map(|x| GraphQLParserTranslator::translate_argument(&x)) + .map(|x| GraphQLParserTranslator::translate_argument(x)) .collect() }) .unwrap_or_else(Vec::new); @@ -300,7 +300,7 @@ fn generate_directives<'a, T>(status: &DeprecationStatus) -> Vec, { - if let Some(d) = deprecation_to_directive(&status) { + if let Some(d) = deprecation_to_directive(status) { vec![d] } else { vec![] diff --git a/juniper/src/tests/fixtures/starwars/schema.rs b/juniper/src/tests/fixtures/starwars/schema.rs index 3b220bdd..7e0431f1 100644 --- a/juniper/src/tests/fixtures/starwars/schema.rs +++ b/juniper/src/tests/fixtures/starwars/schema.rs @@ -361,6 +361,7 @@ impl Database { } pub fn get_character(&self, id: &str) -> Option { + #[allow(clippy::manual_map)] if let Some(h) = self.humans.get(id) { Some(h.clone().into()) } else if let Some(d) = self.droids.get(id) { diff --git a/juniper/src/types/async_await.rs b/juniper/src/types/async_await.rs index 21862771..fdc4a037 100644 --- a/juniper/src/types/async_await.rs +++ b/juniper/src/types/async_await.rs @@ -241,7 +241,7 @@ where let exec_vars = executor.variables(); let sub_exec = executor.field_sub_executor( - &response_name, + response_name, f.name.item, *start_pos, f.selection_set.as_ref().map(|v| &v[..]), @@ -309,7 +309,7 @@ where let type_name = instance.type_name(info); if executor .schema() - .is_named_subtype(&concrete_type_name, &fragment.type_condition.item) + .is_named_subtype(&concrete_type_name, fragment.type_condition.item) || Some(fragment.type_condition.item) == type_name { let sub_result = instance @@ -355,7 +355,7 @@ where let concrete_type_name = instance.concrete_type_name(sub_exec.context(), info); if executor .schema() - .is_named_subtype(&concrete_type_name, &type_condition.item) + .is_named_subtype(&concrete_type_name, type_condition.item) { let sub_result = instance .resolve_into_type_async( diff --git a/juniper/src/types/base.rs b/juniper/src/types/base.rs index 60979a40..45d6b703 100644 --- a/juniper/src/types/base.rs +++ b/juniper/src/types/base.rs @@ -520,7 +520,7 @@ where let type_name = instance.type_name(info); if executor .schema() - .is_named_subtype(&concrete_type_name, &fragment.type_condition.item) + .is_named_subtype(&concrete_type_name, fragment.type_condition.item) || Some(fragment.type_condition.item) == type_name { let sub_result = instance.resolve_into_type( @@ -558,7 +558,7 @@ where let concrete_type_name = instance.concrete_type_name(sub_exec.context(), info); if executor .schema() - .is_named_subtype(&concrete_type_name, &type_condition.item) + .is_named_subtype(&concrete_type_name, type_condition.item) { let sub_result = instance.resolve_into_type( info, diff --git a/juniper/src/types/subscriptions.rs b/juniper/src/types/subscriptions.rs index a6c28fa7..c8ac53af 100644 --- a/juniper/src/types/subscriptions.rs +++ b/juniper/src/types/subscriptions.rs @@ -287,7 +287,7 @@ where start: ref start_pos, .. }) => { - if is_excluded(&f.directives, &executor.variables()) { + if is_excluded(&f.directives, executor.variables()) { continue; } @@ -327,7 +327,7 @@ where f.arguments.as_ref().map(|m| { m.item .iter() - .map(|&(ref k, ref v)| (k.item, v.item.clone().into_const(&exec_vars))) + .map(|&(ref k, ref v)| (k.item, v.item.clone().into_const(exec_vars))) .collect() }), &meta_field.arguments, @@ -361,7 +361,7 @@ where start: ref start_pos, .. }) => { - if is_excluded(&spread.directives, &executor.variables()) { + if is_excluded(&spread.directives, executor.variables()) { continue; } @@ -400,7 +400,7 @@ where start: ref start_pos, .. }) => { - if is_excluded(&fragment.directives, &executor.variables()) { + if is_excluded(&fragment.directives, executor.variables()) { continue; } diff --git a/juniper/src/validation/input_value.rs b/juniper/src/validation/input_value.rs index a24eaac5..ba6803a6 100644 --- a/juniper/src/validation/input_value.rs +++ b/juniper/src/validation/input_value.rs @@ -239,7 +239,7 @@ where match *value { // TODO: avoid this bad duplicate as_str() call. (value system refactor) InputValue::Scalar(ref scalar) if scalar.as_str().is_some() => { - if let Some(ref name) = scalar.as_str() { + if let Some(name) = scalar.as_str() { if !meta.values.iter().any(|ev| ev.name == *name) { errors.push(unification_error( var_name, diff --git a/juniper/src/validation/rules/known_argument_names.rs b/juniper/src/validation/rules/known_argument_names.rs index 390bbe51..6e579977 100644 --- a/juniper/src/validation/rules/known_argument_names.rs +++ b/juniper/src/validation/rules/known_argument_names.rs @@ -74,7 +74,7 @@ where &(ref arg_name, _): &'a (Spanning<&'a str>, Spanning>), ) { if let Some((ref pos, args)) = self.current_args { - if args.iter().find(|a| a.name == arg_name.item).is_none() { + if !args.iter().any(|a| a.name == arg_name.item) { let message = match *pos { ArgumentPosition::Field(field_name, type_name) => { field_error_message(arg_name.item, field_name, type_name) diff --git a/juniper/src/validation/rules/known_directives.rs b/juniper/src/validation/rules/known_directives.rs index 68ccf4ac..012ae1c7 100644 --- a/juniper/src/validation/rules/known_directives.rs +++ b/juniper/src/validation/rules/known_directives.rs @@ -115,11 +115,10 @@ where if let Some(directive_type) = ctx.schema.directive_by_name(directive_name) { if let Some(current_location) = self.location_stack.last() { - if directive_type + if !directive_type .locations .iter() - .find(|l| l == ¤t_location) - .is_none() + .any(|l| l == current_location) { ctx.report_error( &misplaced_error_message(directive_name, current_location), diff --git a/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs b/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs index cf44b552..fc66f342 100644 --- a/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs +++ b/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs @@ -659,7 +659,7 @@ impl<'a, S: Debug> OverlappingFieldsCanBeMerged<'a, S> { item: FragmentSpread { ref name, .. }, .. }) => { - if fragment_names.iter().find(|n| *n == &name.item).is_none() { + if !fragment_names.iter().any(|n| *n == name.item) { fragment_names.push(name.item); } } diff --git a/juniper/src/validation/rules/variables_in_allowed_position.rs b/juniper/src/validation/rules/variables_in_allowed_position.rs index 6391ca68..1f3dff59 100644 --- a/juniper/src/validation/rules/variables_in_allowed_position.rs +++ b/juniper/src/validation/rules/variables_in_allowed_position.rs @@ -20,6 +20,7 @@ pub enum Scope<'a> { pub struct VariableInAllowedPosition<'a, S: Debug + 'a> { spreads: HashMap, HashSet<&'a str>>, variable_usages: HashMap, Vec<(Spanning<&'a String>, Type<'a>)>>, + #[allow(clippy::type_complexity)] variable_defs: HashMap, Vec<&'a (Spanning<&'a str>, VariableDefinition<'a, S>)>>, current_scope: Option>, } diff --git a/juniper_actix/src/lib.rs b/juniper_actix/src/lib.rs index 212c2438..8912e139 100644 --- a/juniper_actix/src/lib.rs +++ b/juniper_actix/src/lib.rs @@ -318,8 +318,9 @@ pub mod subscriptions { I: Init + Send, { fn handle(&mut self, msg: Result, ctx: &mut Self::Context) { - let msg = msg.map(|r| Message(r)); + let msg = msg.map(Message); + #[allow(clippy::single_match)] match msg { Ok(msg) => { let tx = self.graphql_tx.clone(); @@ -413,7 +414,6 @@ pub mod subscriptions { ctx.close(Some(reason)) } }; - () } } #[derive(Message)] @@ -434,7 +434,7 @@ pub mod subscriptions { fn try_from(msg: Message) -> Result { match msg.0 { ws::Message::Text(text) => { - serde_json::from_slice(text.as_bytes()).map_err(|e| Error::Serde(e)) + serde_json::from_slice(text.as_bytes()).map_err(Error::Serde) } ws::Message::Close(_) => Ok(ClientMessage::ConnectionTerminate), _ => Err(Error::UnexpectedClientMessage), diff --git a/juniper_codegen/src/common/field/arg.rs b/juniper_codegen/src/common/field/arg.rs index 0c6d16a9..5dfaa904 100644 --- a/juniper_codegen/src/common/field/arg.rs +++ b/juniper_codegen/src/common/field/arg.rs @@ -194,7 +194,6 @@ impl Attr { /// Checks whether this [`Attr`] doesn't contain arguments related to an /// [`OnField`] argument. - #[must_use] fn ensure_no_regular_arguments(&self) -> syn::Result<()> { if let Some(span) = &self.name { return Err(Self::err_disallowed(&span, "name")); diff --git a/juniper_codegen/src/util/mod.rs b/juniper_codegen/src/util/mod.rs index 5648b8c3..ae84fa65 100644 --- a/juniper_codegen/src/util/mod.rs +++ b/juniper_codegen/src/util/mod.rs @@ -552,7 +552,7 @@ pub struct FieldAttributes { impl Parse for FieldAttributes { fn parse(input: ParseStream<'_>) -> syn::Result { - let items = Punctuated::::parse_terminated(&input)?; + let items = Punctuated::::parse_terminated(input)?; let mut output = Self::default(); @@ -592,8 +592,8 @@ impl FieldAttributes { attrs: &[syn::Attribute], _mode: FieldAttributeParseMode, ) -> syn::Result { - let doc_comment = get_doc_comment(&attrs); - let deprecation = get_deprecated(&attrs); + let doc_comment = get_doc_comment(attrs); + let deprecation = get_deprecated(attrs); let attr_opt = attrs.iter().find(|attr| attr.path.is_ident("graphql")); diff --git a/juniper_warp/src/lib.rs b/juniper_warp/src/lib.rs index 4c683e92..677a992a 100644 --- a/juniper_warp/src/lib.rs +++ b/juniper_warp/src/lib.rs @@ -462,11 +462,11 @@ pub mod subscriptions { let (ws_tx, ws_rx) = websocket.split(); let (s_tx, s_rx) = Connection::new(ArcSchema(root_node), init).split(); - let ws_rx = ws_rx.map(|r| r.map(|msg| Message(msg))); + let ws_rx = ws_rx.map(|r| r.map(Message)); let s_rx = s_rx.map(|msg| { serde_json::to_string(&msg) - .map(|t| warp::ws::Message::text(t)) - .map_err(|e| Error::Serde(e)) + .map(warp::ws::Message::text) + .map_err(Error::Serde) }); match future::select(