Make Clippy almost happy on latest Rust
This commit is contained in:
parent
dc99ae70b8
commit
70bc9c4512
21 changed files with 100 additions and 156 deletions
|
@ -146,7 +146,9 @@ pub enum Definition<'a, S> {
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub type Document<'a, S> = Vec<Definition<'a, S>>;
|
||||
pub type Document<'a, S> = [Definition<'a, S>];
|
||||
#[doc(hidden)]
|
||||
pub type OwnedDocument<'a, S> = Vec<Definition<'a, S>>;
|
||||
|
||||
/// Parse an unstructured input value into a Rust data type.
|
||||
///
|
||||
|
@ -381,7 +383,7 @@ where
|
|||
///
|
||||
/// This constructs a new IndexMap that contain references to the keys
|
||||
/// and values in `self`.
|
||||
pub fn to_object_value<'a>(&'a self) -> Option<IndexMap<&'a str, &'a Self>> {
|
||||
pub fn to_object_value(&self) -> Option<IndexMap<&str, &Self>> {
|
||||
match *self {
|
||||
InputValue::Object(ref o) => Some(
|
||||
o.iter()
|
||||
|
|
|
@ -440,7 +440,7 @@ impl<'a, S> LookAheadMethods<'a, S> for LookAheadSelection<'a, S> {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
ast::Document,
|
||||
ast::{Document, OwnedDocument},
|
||||
parser::UnlocatedParseResult,
|
||||
schema::model::SchemaType,
|
||||
validation::test_harness::{MutationRoot, QueryRoot, SubscriptionRoot},
|
||||
|
@ -448,7 +448,7 @@ mod tests {
|
|||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn parse_document_source<S>(q: &str) -> UnlocatedParseResult<Document<S>>
|
||||
fn parse_document_source<S>(q: &str) -> UnlocatedParseResult<OwnedDocument<S>>
|
||||
where
|
||||
S: ScalarValue,
|
||||
{
|
||||
|
|
|
@ -326,6 +326,7 @@ where
|
|||
{
|
||||
type Type = T;
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn into(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, Option<T>)>, S> {
|
||||
Ok(self.map(|(ctx, v)| (ctx, Some(v))))
|
||||
}
|
||||
|
@ -353,6 +354,7 @@ where
|
|||
{
|
||||
type Type = T;
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn into(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, Option<T>)>, S2> {
|
||||
self.map(|o| o.map(|(ctx, v)| (ctx, Some(v))))
|
||||
.map_err(FieldError::map_scalar_value)
|
||||
|
|
|
@ -112,16 +112,8 @@ where
|
|||
Executor {
|
||||
fragments: &self.fragments,
|
||||
variables: &self.variables,
|
||||
current_selection_set: if let Some(s) = &self.current_selection_set {
|
||||
Some(&s[..])
|
||||
} else {
|
||||
None
|
||||
},
|
||||
parent_selection_set: if let Some(s) = &self.parent_selection_set {
|
||||
Some(&s[..])
|
||||
} else {
|
||||
None
|
||||
},
|
||||
current_selection_set: self.current_selection_set.as_deref(),
|
||||
parent_selection_set: self.parent_selection_set.as_deref(),
|
||||
current_type: self.current_type.clone(),
|
||||
schema: self.schema,
|
||||
context: self.context,
|
||||
|
|
|
@ -319,7 +319,7 @@ where
|
|||
SubscriptionT::TypeInfo: Sync,
|
||||
S: ScalarValue + Send + Sync,
|
||||
{
|
||||
let document: crate::ast::Document<'a, S> =
|
||||
let document: crate::ast::OwnedDocument<'a, S> =
|
||||
parse_document_source(document_source, &root_node.schema)?;
|
||||
|
||||
{
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use crate::ast::{
|
||||
Arguments, Definition, Directive, Document, Field, Fragment, FragmentSpread, InlineFragment,
|
||||
InputValue, Operation, OperationType, Selection, Type, VariableDefinition, VariableDefinitions,
|
||||
Arguments, Definition, Directive, Field, Fragment, FragmentSpread, InlineFragment, InputValue,
|
||||
Operation, OperationType, OwnedDocument, Selection, Type, VariableDefinition,
|
||||
VariableDefinitions,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
@ -21,7 +22,7 @@ use crate::{
|
|||
pub fn parse_document_source<'a, 'b, S>(
|
||||
s: &'a str,
|
||||
schema: &'b SchemaType<'b, S>,
|
||||
) -> UnlocatedParseResult<'a, Document<'a, S>>
|
||||
) -> UnlocatedParseResult<'a, OwnedDocument<'a, S>>
|
||||
where
|
||||
S: ScalarValue,
|
||||
{
|
||||
|
@ -33,7 +34,7 @@ where
|
|||
fn parse_document<'a, 'b, S>(
|
||||
parser: &mut Parser<'a>,
|
||||
schema: &'b SchemaType<'b, S>,
|
||||
) -> UnlocatedParseResult<'a, Document<'a, S>>
|
||||
) -> UnlocatedParseResult<'a, OwnedDocument<'a, S>>
|
||||
where
|
||||
S: ScalarValue,
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::{
|
||||
ast::{
|
||||
Arguments, Definition, Document, Field, InputValue, Operation, OperationType, Selection,
|
||||
Arguments, Definition, Field, InputValue, Operation, OperationType, OwnedDocument,
|
||||
Selection,
|
||||
},
|
||||
parser::{document::parse_document_source, ParseError, SourcePosition, Spanning, Token},
|
||||
schema::model::SchemaType,
|
||||
|
@ -9,7 +10,7 @@ use crate::{
|
|||
value::{DefaultScalarValue, ScalarValue},
|
||||
};
|
||||
|
||||
fn parse_document<S>(s: &str) -> Document<S>
|
||||
fn parse_document<S>(s: &str) -> OwnedDocument<S>
|
||||
where
|
||||
S: ScalarValue,
|
||||
{
|
||||
|
|
|
@ -293,14 +293,10 @@ impl<'a, S> SchemaType<'a, S> {
|
|||
|
||||
/// Get the mutation type from the schema.
|
||||
pub fn mutation_type(&self) -> Option<TypeType<S>> {
|
||||
if let Some(ref mutation_type_name) = self.mutation_type_name {
|
||||
Some(
|
||||
self.type_by_name(mutation_type_name)
|
||||
.expect("Mutation type does not exist in schema"),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
self.mutation_type_name.as_ref().map(|name| {
|
||||
self.type_by_name(name)
|
||||
.expect("Mutation type does not exist in schema")
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the concrete mutation type from the schema.
|
||||
|
@ -313,14 +309,10 @@ impl<'a, S> SchemaType<'a, S> {
|
|||
|
||||
/// Get the subscription type.
|
||||
pub fn subscription_type(&self) -> Option<TypeType<S>> {
|
||||
if let Some(ref subscription_type_name) = self.subscription_type_name {
|
||||
Some(
|
||||
self.type_by_name(subscription_type_name)
|
||||
.expect("Subscription type does not exist in schema"),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
self.subscription_type_name.as_ref().map(|name| {
|
||||
self.type_by_name(name)
|
||||
.expect("Subscription type does not exist in schema")
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the concrete subscription type.
|
||||
|
|
|
@ -299,7 +299,6 @@ where
|
|||
S: ScalarValue + Send + Sync,
|
||||
{
|
||||
use futures::stream::{FuturesOrdered, StreamExt as _};
|
||||
use std::iter::FromIterator;
|
||||
|
||||
let stop_on_null = executor
|
||||
.current_type()
|
||||
|
@ -307,8 +306,9 @@ where
|
|||
.expect("Current type is not a list type")
|
||||
.is_non_null();
|
||||
|
||||
let iter = items.map(|it| async move { executor.resolve_into_value_async(info, it).await });
|
||||
let mut futures = FuturesOrdered::from_iter(iter);
|
||||
let mut futures = items
|
||||
.map(|it| async move { executor.resolve_into_value_async(info, it).await })
|
||||
.collect::<FuturesOrdered<_>>();
|
||||
|
||||
let mut values = Vec::with_capacity(futures.len());
|
||||
while let Some(value) = futures.next().await {
|
||||
|
|
|
@ -94,10 +94,7 @@ where
|
|||
T: FromInputValue<S>,
|
||||
{
|
||||
fn from_input_value(v: &InputValue<S>) -> Option<Box<T>> {
|
||||
match <T as FromInputValue<S>>::from_input_value(v) {
|
||||
Some(v) => Some(Box::new(v)),
|
||||
None => None,
|
||||
}
|
||||
<T as FromInputValue<S>>::from_input_value(v).map(Box::new)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -289,10 +286,7 @@ where
|
|||
T: FromInputValue<S>,
|
||||
{
|
||||
fn from_input_value(v: &InputValue<S>) -> Option<Arc<T>> {
|
||||
match <T as FromInputValue<S>>::from_input_value(v) {
|
||||
Some(v) => Some(Arc::new(v)),
|
||||
None => None,
|
||||
}
|
||||
<T as FromInputValue<S>>::from_input_value(v).map(Arc::new)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -230,19 +230,11 @@ where
|
|||
self.1.exit_list_value(ctx, l);
|
||||
}
|
||||
|
||||
fn enter_object_value(
|
||||
&mut self,
|
||||
ctx: &mut ValidatorContext<'a, S>,
|
||||
o: Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>,
|
||||
) {
|
||||
fn enter_object_value(&mut self, ctx: &mut ValidatorContext<'a, S>, o: SpannedObject<'a, S>) {
|
||||
self.0.enter_object_value(ctx, o);
|
||||
self.1.enter_object_value(ctx, o);
|
||||
}
|
||||
fn exit_object_value(
|
||||
&mut self,
|
||||
ctx: &mut ValidatorContext<'a, S>,
|
||||
o: Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>,
|
||||
) {
|
||||
fn exit_object_value(&mut self, ctx: &mut ValidatorContext<'a, S>, o: SpannedObject<'a, S>) {
|
||||
self.0.exit_object_value(ctx, o);
|
||||
self.1.exit_object_value(ctx, o);
|
||||
}
|
||||
|
@ -264,3 +256,5 @@ where
|
|||
self.1.exit_object_field(ctx, f);
|
||||
}
|
||||
}
|
||||
|
||||
type SpannedObject<'a, S> = Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>;
|
||||
|
|
|
@ -21,19 +21,11 @@ impl<'a, S> Visitor<'a, S> for UniqueInputFieldNames<'a>
|
|||
where
|
||||
S: ScalarValue,
|
||||
{
|
||||
fn enter_object_value(
|
||||
&mut self,
|
||||
_: &mut ValidatorContext<'a, S>,
|
||||
_: Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>,
|
||||
) {
|
||||
fn enter_object_value(&mut self, _: &mut ValidatorContext<'a, S>, _: SpannedObject<'a, S>) {
|
||||
self.known_name_stack.push(HashMap::new());
|
||||
}
|
||||
|
||||
fn exit_object_value(
|
||||
&mut self,
|
||||
_: &mut ValidatorContext<'a, S>,
|
||||
_: Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>,
|
||||
) {
|
||||
fn exit_object_value(&mut self, _: &mut ValidatorContext<'a, S>, _: SpannedObject<'a, S>) {
|
||||
self.known_name_stack.pop();
|
||||
}
|
||||
|
||||
|
@ -58,6 +50,8 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
type SpannedObject<'a, S> = Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>;
|
||||
|
||||
fn error_message(field_name: &str) -> String {
|
||||
format!("There can only be one input field named \"{}\"", field_name)
|
||||
}
|
||||
|
|
|
@ -865,7 +865,9 @@ where
|
|||
let mut ctx = ValidatorContext::new(unsafe { ::std::mem::transmute(&root.schema) }, &doc);
|
||||
|
||||
let mut mv = MultiVisitorNil.with(factory());
|
||||
visit(&mut mv, &mut ctx, unsafe { ::std::mem::transmute(&doc) });
|
||||
visit(&mut mv, &mut ctx, unsafe {
|
||||
::std::mem::transmute(doc.as_slice())
|
||||
});
|
||||
|
||||
ctx.into_errors()
|
||||
}
|
||||
|
|
|
@ -128,18 +128,8 @@ where
|
|||
) {
|
||||
}
|
||||
|
||||
fn enter_object_value(
|
||||
&mut self,
|
||||
_: &mut ValidatorContext<'a, S>,
|
||||
_: Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>,
|
||||
) {
|
||||
}
|
||||
fn exit_object_value(
|
||||
&mut self,
|
||||
_: &mut ValidatorContext<'a, S>,
|
||||
_: Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>,
|
||||
) {
|
||||
}
|
||||
fn enter_object_value(&mut self, _: &mut ValidatorContext<'a, S>, _: SpannedObject<'a, S>) {}
|
||||
fn exit_object_value(&mut self, _: &mut ValidatorContext<'a, S>, _: SpannedObject<'a, S>) {}
|
||||
|
||||
fn enter_object_field(
|
||||
&mut self,
|
||||
|
@ -154,3 +144,5 @@ where
|
|||
) {
|
||||
}
|
||||
}
|
||||
|
||||
type SpannedObject<'a, S> = Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>;
|
||||
|
|
|
@ -73,10 +73,7 @@ where
|
|||
operation_name,
|
||||
variables,
|
||||
} = get_req;
|
||||
let variables = match variables {
|
||||
Some(variables) => Some(serde_json::from_str(&variables).unwrap()),
|
||||
None => None,
|
||||
};
|
||||
let variables = variables.map(|s| serde_json::from_str(&s).unwrap());
|
||||
Self::new(query, operation_name, variables)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,13 +25,11 @@ struct ScalarCodegenInput {
|
|||
fn get_first_method_arg(
|
||||
inputs: syn::punctuated::Punctuated<syn::FnArg, syn::Token![,]>,
|
||||
) -> Option<syn::Ident> {
|
||||
if let Some(fn_arg) = inputs.first() {
|
||||
if let syn::FnArg::Typed(pat_type) = fn_arg {
|
||||
if let Some(syn::FnArg::Typed(pat_type)) = inputs.first() {
|
||||
if let syn::Pat::Ident(pat_ident) = &*pat_type.pat {
|
||||
return Some(pat_ident.ident.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
@ -45,23 +43,16 @@ fn get_method_return_type(output: syn::ReturnType) -> Option<syn::Type> {
|
|||
|
||||
// Find the enum type by inspecting the type parameter on the return value
|
||||
fn get_enum_type(return_type: &Option<syn::Type>) -> Option<syn::PathSegment> {
|
||||
if let Some(return_type) = return_type {
|
||||
match return_type {
|
||||
syn::Type::Path(type_path) => {
|
||||
if let Some(syn::Type::Path(type_path)) = return_type {
|
||||
let path_segment = type_path
|
||||
.path
|
||||
.segments
|
||||
.iter()
|
||||
.find(|ps| match ps.arguments {
|
||||
syn::PathArguments::AngleBracketed(_) => true,
|
||||
_ => false,
|
||||
});
|
||||
.find(|ps| matches!(ps.arguments, syn::PathArguments::AngleBracketed(_)));
|
||||
|
||||
if let Some(path_segment) = path_segment {
|
||||
match &path_segment.arguments {
|
||||
syn::PathArguments::AngleBracketed(generic_args) => {
|
||||
let generic_type_arg =
|
||||
generic_args.args.iter().find(|generic_type_arg| {
|
||||
if let syn::PathArguments::AngleBracketed(generic_args) = &path_segment.arguments {
|
||||
let generic_type_arg = generic_args.args.iter().find(|generic_type_arg| {
|
||||
matches!(generic_type_arg, syn::GenericArgument::Type(_))
|
||||
});
|
||||
|
||||
|
@ -73,11 +64,6 @@ fn get_enum_type(return_type: &Option<syn::Type>) -> Option<syn::PathSegment> {
|
|||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,8 +95,8 @@ impl syn::parse::Parse for ScalarCodegenInput {
|
|||
}
|
||||
|
||||
for impl_item in parse_custom_scalar_value_impl.items {
|
||||
match impl_item {
|
||||
syn::ImplItem::Method(method) => match method.sig.ident.to_string().as_str() {
|
||||
if let syn::ImplItem::Method(method) = impl_item {
|
||||
match method.sig.ident.to_string().as_str() {
|
||||
"resolve" => {
|
||||
resolve_body = Some(method.block);
|
||||
}
|
||||
|
@ -130,9 +116,8 @@ impl syn::parse::Parse for ScalarCodegenInput {
|
|||
from_str_body = Some(method.block);
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
_ => (),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let custom_data_type = if custom_data_type_is_struct {
|
||||
|
|
|
@ -161,7 +161,7 @@ fn join_doc_strings(docs: &[String]) -> String {
|
|||
docs.iter()
|
||||
.map(|s| s.as_str().trim_end())
|
||||
// Trim leading space.
|
||||
.map(|s| if s.starts_with(' ') { &s[1..] } else { s })
|
||||
.map(|s| s.strip_prefix(' ').unwrap_or(s))
|
||||
// Add newline, exept when string ends in a continuation backslash or is the last line.
|
||||
.enumerate()
|
||||
.fold(String::new(), |mut buffer, (index, s)| {
|
||||
|
@ -227,13 +227,11 @@ pub fn to_camel_case(s: &str) -> String {
|
|||
|
||||
// Handle `_` and `__` to be more friendly with the `_var` convention for unused variables, and
|
||||
// GraphQL introspection identifiers.
|
||||
let s_iter = if s.starts_with("__") {
|
||||
let s_iter = if let Some(s) = s.strip_prefix("__") {
|
||||
dest.push_str("__");
|
||||
&s[2..]
|
||||
} else if s.starts_with('_') {
|
||||
&s[1..]
|
||||
} else {
|
||||
s
|
||||
} else {
|
||||
s.strip_prefix('_').unwrap_or(s)
|
||||
}
|
||||
.split('_')
|
||||
.enumerate();
|
||||
|
@ -434,9 +432,10 @@ impl ObjectAttributes {
|
|||
}
|
||||
Ok(a)
|
||||
} else {
|
||||
let mut a = Self::default();
|
||||
a.description = get_doc_comment(attrs);
|
||||
Ok(a)
|
||||
Ok(Self {
|
||||
description: get_doc_comment(attrs),
|
||||
..Self::default()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -500,7 +499,7 @@ enum FieldAttribute {
|
|||
Deprecation(SpanContainer<DeprecationAttr>),
|
||||
Skip(SpanContainer<syn::Ident>),
|
||||
Arguments(HashMap<String, FieldAttributeArgument>),
|
||||
Default(SpanContainer<Option<syn::Expr>>),
|
||||
Default(Box<SpanContainer<Option<syn::Expr>>>),
|
||||
}
|
||||
|
||||
impl Parse for FieldAttribute {
|
||||
|
@ -573,7 +572,7 @@ impl Parse for FieldAttribute {
|
|||
SpanContainer::new(ident.span(), None, None)
|
||||
};
|
||||
|
||||
Ok(FieldAttribute::Default(default_expr))
|
||||
Ok(FieldAttribute::Default(Box::new(default_expr)))
|
||||
}
|
||||
_ => Err(syn::Error::new(ident.span(), "unknown attribute")),
|
||||
}
|
||||
|
@ -617,7 +616,7 @@ impl Parse for FieldAttributes {
|
|||
output.arguments = args;
|
||||
}
|
||||
FieldAttribute::Default(expr) => {
|
||||
output.default = Some(expr);
|
||||
output.default = Some(*expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ impl<T: ToTokens> ToTokens for SpanContainer<T> {
|
|||
|
||||
impl<T> SpanContainer<T> {
|
||||
pub fn new(ident: Span, expr: Option<Span>, val: T) -> Self {
|
||||
Self { ident, expr, val }
|
||||
Self { expr, ident, val }
|
||||
}
|
||||
|
||||
pub fn span_ident(&self) -> Span {
|
||||
|
|
|
@ -486,6 +486,7 @@ enum ConnectionSinkState<S: Schema, I: Init<S::ScalarValue, S::Context>> {
|
|||
state: ConnectionState<S, I>,
|
||||
},
|
||||
HandlingMessage {
|
||||
#[allow(clippy::type_complexity)]
|
||||
result: BoxFuture<'static, (ConnectionState<S, I>, BoxStream<'static, Reaction<S>>)>,
|
||||
},
|
||||
Closed,
|
||||
|
@ -607,7 +608,6 @@ where
|
|||
}
|
||||
|
||||
// Poll the reactions for new outgoing messages.
|
||||
loop {
|
||||
if !self.reactions.is_empty() {
|
||||
match Pin::new(&mut self.reactions).poll_next(cx) {
|
||||
Poll::Ready(Some(reaction)) => match reaction {
|
||||
|
@ -619,14 +619,11 @@ where
|
|||
// happen if the first message we receive does not require any reaction. Just
|
||||
// recreate it in that case.
|
||||
self.reactions = SelectAll::new();
|
||||
return Poll::Pending;
|
||||
}
|
||||
Poll::Pending => return Poll::Pending,
|
||||
}
|
||||
} else {
|
||||
return Poll::Pending;
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
Poll::Pending
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,9 +39,9 @@ pub struct ErrorPayload {
|
|||
impl ErrorPayload {
|
||||
/// For this to be okay, the caller must guarantee that the error can only reference data from
|
||||
/// execution_params and that execution_params has not been modified or moved.
|
||||
pub(crate) unsafe fn new_unchecked<'a>(
|
||||
pub(crate) unsafe fn new_unchecked(
|
||||
execution_params: Box<dyn Any + Send>,
|
||||
error: GraphQLError<'a>,
|
||||
error: GraphQLError<'_>,
|
||||
) -> Self {
|
||||
Self {
|
||||
_execution_params: Some(execution_params),
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
merge_imports = true
|
||||
imports_granularity = "Crate"
|
||||
use_field_init_shorthand = true
|
||||
|
|
Loading…
Reference in a new issue