Fix some clippy lints (#809)

This commit is contained in:
Christian Legnitto 2020-12-10 21:41:23 -10:00 committed by GitHub
parent b418869f95
commit 6326acde33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 44 additions and 92 deletions

View file

@ -81,9 +81,9 @@ async fn main() {
let homepage = warp::path::end().map(|| { let homepage = warp::path::end().map(|| {
Response::builder() Response::builder()
.header("content-type", "text/html") .header("content-type", "text/html")
.body(format!( .body(
"<html><h1>juniper_warp</h1><div>visit <a href=\"/graphiql\">/graphiql</a></html>" "<html><h1>juniper_warp</h1><div>visit <a href=\"/graphiql\">/graphiql</a></html>",
)) )
}); });
log::info!("Listening on 127.0.0.1:8080"); log::info!("Listening on 127.0.0.1:8080");

View file

@ -192,10 +192,7 @@ impl<'a> Type<'a> {
/// Determines if a type only can represent non-null values. /// Determines if a type only can represent non-null values.
pub fn is_non_null(&self) -> bool { pub fn is_non_null(&self) -> bool {
match *self { matches!(*self, Type::NonNullNamed(_) | Type::NonNullList(_))
Type::NonNullNamed(_) | Type::NonNullList(_) => true,
_ => false,
}
} }
} }
@ -328,18 +325,12 @@ where
/// Does the value represent null? /// Does the value represent null?
pub fn is_null(&self) -> bool { pub fn is_null(&self) -> bool {
match *self { matches!(*self, InputValue::Null)
InputValue::Null => true,
_ => false,
}
} }
/// Does the value represent a variable? /// Does the value represent a variable?
pub fn is_variable(&self) -> bool { pub fn is_variable(&self) -> bool {
match *self { matches!(*self, InputValue::Variable(_))
InputValue::Variable(_) => true,
_ => false,
}
} }
/// View the underlying enum value, if present. /// View the underlying enum value, if present.

View file

@ -513,15 +513,15 @@ fn is_source_char(c: char) -> bool {
} }
fn is_name_start(c: char) -> bool { fn is_name_start(c: char) -> bool {
c == '_' || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') c == '_' || ('A'..='Z').contains(&c) || ('a'..='z').contains(&c)
} }
fn is_name_cont(c: char) -> bool { fn is_name_cont(c: char) -> bool {
is_name_start(c) || (c >= '0' && c <= '9') is_name_start(c) || ('0'..='9').contains(&c)
} }
fn is_number_start(c: char) -> bool { fn is_number_start(c: char) -> bool {
c == '-' || (c >= '0' && c <= '9') c == '-' || ('0'..='9').contains(&c)
} }
impl fmt::Display for LexerError { impl fmt::Display for LexerError {

View file

@ -348,40 +348,28 @@ impl<'a, S> MetaType<'a, S> {
/// ///
/// Objects, interfaces, and unions are composite. /// Objects, interfaces, and unions are composite.
pub fn is_composite(&self) -> bool { pub fn is_composite(&self) -> bool {
match *self { matches!(*self, MetaType::Object(_) | MetaType::Interface(_) | MetaType::Union(_))
MetaType::Object(_) | MetaType::Interface(_) | MetaType::Union(_) => true,
_ => false,
}
} }
/// Returns true if the type can occur in leaf positions in queries /// Returns true if the type can occur in leaf positions in queries
/// ///
/// Only enums and scalars are leaf types. /// Only enums and scalars are leaf types.
pub fn is_leaf(&self) -> bool { pub fn is_leaf(&self) -> bool {
match *self { matches!(*self, MetaType::Enum(_) | MetaType::Scalar(_))
MetaType::Enum(_) | MetaType::Scalar(_) => true,
_ => false,
}
} }
/// Returns true if the type is abstract /// Returns true if the type is abstract
/// ///
/// Only interfaces and unions are abstract types. /// Only interfaces and unions are abstract types.
pub fn is_abstract(&self) -> bool { pub fn is_abstract(&self) -> bool {
match *self { matches!(*self, MetaType::Interface(_) | MetaType::Union(_))
MetaType::Interface(_) | MetaType::Union(_) => true,
_ => false,
}
} }
/// Returns true if the type can be used in input positions, e.g. arguments or variables /// Returns true if the type can be used in input positions, e.g. arguments or variables
/// ///
/// Only scalars, enums, and input objects are input types. /// Only scalars, enums, and input objects are input types.
pub fn is_input(&self) -> bool { pub fn is_input(&self) -> bool {
match *self { matches!(*self, MetaType::Scalar(_) | MetaType::Enum(_) | MetaType::InputObject(_))
MetaType::Scalar(_) | MetaType::Enum(_) | MetaType::InputObject(_) => true,
_ => false,
}
} }
/// Returns true if the type is built-in to GraphQL. /// Returns true if the type is built-in to GraphQL.

View file

@ -367,7 +367,7 @@ impl<'a, S> SchemaType<'a, S> {
/// Determine if there is an overlap between types. /// Determine if there is an overlap between types.
pub fn type_overlap(&self, t1: &MetaType<S>, t2: &MetaType<S>) -> bool { pub fn type_overlap(&self, t1: &MetaType<S>, t2: &MetaType<S>) -> bool {
if (t1 as *const MetaType<S>) == (t2 as *const MetaType<S>) { if std::ptr::eq(t1, t2) {
return true; return true;
} }
@ -414,7 +414,7 @@ impl<'a, S> SchemaType<'a, S> {
) -> bool { ) -> bool {
self.possible_types(abstract_type) self.possible_types(abstract_type)
.into_iter() .into_iter()
.any(|t| (t as *const MetaType<S>) == (possible_type as *const MetaType<S>)) .any(|t| (std::ptr::eq(t, possible_type)))
} }
/// If the type is a subtype of another type. /// If the type is a subtype of another type.
@ -483,10 +483,7 @@ impl<'a, S> TypeType<'a, S> {
#[inline] #[inline]
pub fn is_non_null(&self) -> bool { pub fn is_non_null(&self) -> bool {
match *self { matches!(*self, TypeType::NonNull(_))
TypeType::NonNull(_) => true,
_ => false,
}
} }
} }

View file

@ -9,11 +9,11 @@ use std::{
// stabilise (https://github.com/rust-lang/rust/issues/39658). // stabilise (https://github.com/rust-lang/rust/issues/39658).
fn is_ascii_alphabetic(c: char) -> bool { fn is_ascii_alphabetic(c: char) -> bool {
c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' ('a'..='z').contains(&c) || ('A'..='Z').contains(&c)
} }
fn is_ascii_digit(c: char) -> bool { fn is_ascii_digit(c: char) -> bool {
c >= '0' && c <= '9' ('0'..='9').contains(&c)
} }
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]

View file

@ -48,37 +48,25 @@ impl<T> Nullable<T> {
/// Returns `true` if the nullable is a `ExplicitNull` value. /// Returns `true` if the nullable is a `ExplicitNull` value.
#[inline] #[inline]
pub fn is_explicit_null(&self) -> bool { pub fn is_explicit_null(&self) -> bool {
match self { matches!(self, Self::ExplicitNull)
Self::ExplicitNull => true,
_ => false,
}
} }
/// Returns `true` if the nullable is a `ImplicitNull` value. /// Returns `true` if the nullable is a `ImplicitNull` value.
#[inline] #[inline]
pub fn is_implicit_null(&self) -> bool { pub fn is_implicit_null(&self) -> bool {
match self { matches!(self, Self::ImplicitNull)
Self::ImplicitNull => true,
_ => false,
}
} }
/// Returns `true` if the nullable is a `Some` value. /// Returns `true` if the nullable is a `Some` value.
#[inline] #[inline]
pub fn is_some(&self) -> bool { pub fn is_some(&self) -> bool {
match self { matches!(self, Self::Some(_))
Self::Some(_) => true,
_ => false,
}
} }
/// Returns `true` if the nullable is not a `Some` value. /// Returns `true` if the nullable is not a `Some` value.
#[inline] #[inline]
pub fn is_null(&self) -> bool { pub fn is_null(&self) -> bool {
match self { !matches!(self, Self::Some(_))
Self::Some(_) => false,
_ => true,
}
} }
/// Converts from `&mut Nullable<T>` to `Nullable<&mut T>`. /// Converts from `&mut Nullable<T>` to `Nullable<&mut T>`.

View file

@ -9,9 +9,13 @@ pub fn to_camel_case(s: &'_ str) -> Cow<'_, str> {
// handle '_' to be more friendly with the // handle '_' to be more friendly with the
// _var convention for unused variables // _var convention for unused variables
let s_iter = if s.starts_with('_') { &s[1..] } else { s } let s_iter = if let Some(stripped) = s.strip_prefix('_') {
.split('_') stripped
.enumerate(); } else {
s
}
.split('_')
.enumerate();
for (i, part) in s_iter { for (i, part) in s_iter {
if i > 0 && part.len() == 1 { if i > 0 && part.len() == 1 {

View file

@ -587,10 +587,8 @@ impl<'a, S: Debug> OverlappingFieldsCanBeMerged<'a, S> {
} }
fn is_object_type(&self, ctx: &ValidatorContext<'a, S>, type_name: Option<&str>) -> bool { fn is_object_type(&self, ctx: &ValidatorContext<'a, S>, type_name: Option<&str>) -> bool {
match type_name.and_then(|n| ctx.schema.concrete_type_by_name(n)) { let meta = type_name.and_then(|n| ctx.schema.concrete_type_by_name(n));
Some(&MetaType::Object(_)) => true, matches!(meta, Some(&MetaType::Object(_)))
_ => false,
}
} }
fn get_referenced_fields_and_fragment_names( fn get_referenced_fields_and_fragment_names(

View file

@ -89,10 +89,7 @@ impl<S: ScalarValue> Value<S> {
/// Does this value represent null? /// Does this value represent null?
pub fn is_null(&self) -> bool { pub fn is_null(&self) -> bool {
match *self { matches!(*self, Self::Null)
Self::Null => true,
_ => false,
}
} }
/// View the underlying scalar value if present /// View the underlying scalar value if present

View file

@ -62,10 +62,7 @@ fn get_enum_type(return_type: &Option<syn::Type>) -> Option<syn::PathSegment> {
syn::PathArguments::AngleBracketed(generic_args) => { syn::PathArguments::AngleBracketed(generic_args) => {
let generic_type_arg = let generic_type_arg =
generic_args.args.iter().find(|generic_type_arg| { generic_args.args.iter().find(|generic_type_arg| {
match generic_type_arg { matches!(generic_type_arg, syn::GenericArgument::Type(_))
syn::GenericArgument::Type(_) => true,
_ => false,
}
}); });
if let Some(syn::GenericArgument::Type(syn::Type::Path(type_path))) = if let Some(syn::GenericArgument::Type(syn::Type::Path(type_path))) =

View file

@ -97,7 +97,7 @@ enum Reaction<S: Schema> {
impl<S: Schema> Reaction<S> { impl<S: Schema> Reaction<S> {
/// Converts the reaction into a one-item stream. /// Converts the reaction into a one-item stream.
fn to_stream(self) -> BoxStream<'static, Self> { fn into_stream(self) -> BoxStream<'static, Self> {
stream::once(future::ready(self)).boxed() stream::once(future::ready(self)).boxed()
} }
} }
@ -153,7 +153,7 @@ impl<S: Schema, I: Init<S::ScalarValue, S::Context>> ConnectionState<S, I> {
msg: ClientMessage<S::ScalarValue>, msg: ClientMessage<S::ScalarValue>,
) -> (Self, BoxStream<'static, Reaction<S>>) { ) -> (Self, BoxStream<'static, Reaction<S>>) {
if let ClientMessage::ConnectionTerminate = msg { if let ClientMessage::ConnectionTerminate = msg {
return (self, Reaction::EndStream.to_stream()); return (self, Reaction::EndStream.into_stream());
} }
match self { match self {
@ -171,7 +171,7 @@ impl<S: Schema, I: Init<S::ScalarValue, S::Context>> ConnectionState<S, I> {
s = s s = s
.chain( .chain(
Reaction::ServerMessage(ServerMessage::ConnectionKeepAlive) Reaction::ServerMessage(ServerMessage::ConnectionKeepAlive)
.to_stream(), .into_stream(),
) )
.boxed(); .boxed();
s = s s = s
@ -270,7 +270,7 @@ impl<S: Schema, I: Init<S::ScalarValue, S::Context>> ConnectionState<S, I> {
// Once the stream ends, send the Complete message. // Once the stream ends, send the Complete message.
let s = s.chain( let s = s.chain(
Reaction::ServerMessage(ServerMessage::Complete { id }) Reaction::ServerMessage(ServerMessage::Complete { id })
.to_stream(), .into_stream(),
); );
s.boxed() s.boxed()
@ -306,11 +306,7 @@ impl<S: Schema, I: Init<S::ScalarValue, S::Context>> ConnectionState<S, I> {
// Try to execute this as a query or mutation. // Try to execute this as a query or mutation.
match juniper::execute( match juniper::execute(
&params.start_payload.query, &params.start_payload.query,
params params.start_payload.operation_name.as_deref(),
.start_payload
.operation_name
.as_ref()
.map(|s| s.as_str()),
params.schema.root_node(), params.schema.root_node(),
&params.start_payload.variables, &params.start_payload.variables,
&params.config.context, &params.config.context,
@ -322,7 +318,7 @@ impl<S: Schema, I: Init<S::ScalarValue, S::Context>> ConnectionState<S, I> {
id: id.clone(), id: id.clone(),
payload: DataPayload { data, errors }, payload: DataPayload { data, errors },
}) })
.to_stream(); .into_stream();
} }
Err(GraphQLError::IsSubscription) => {} Err(GraphQLError::IsSubscription) => {}
Err(e) => { Err(e) => {
@ -331,7 +327,7 @@ impl<S: Schema, I: Init<S::ScalarValue, S::Context>> ConnectionState<S, I> {
// e only references data owned by params. The new ErrorPayload will continue to keep that data alive. // e only references data owned by params. The new ErrorPayload will continue to keep that data alive.
payload: unsafe { ErrorPayload::new_unchecked(Box::new(params.clone()), e) }, payload: unsafe { ErrorPayload::new_unchecked(Box::new(params.clone()), e) },
}) })
.to_stream(); .into_stream();
} }
} }
@ -423,11 +419,7 @@ impl<S: Schema> Stream for SubscriptionStart<S> {
future: unsafe { future: unsafe {
juniper::resolve_into_stream( juniper::resolve_into_stream(
&(*params).start_payload.query, &(*params).start_payload.query,
(*params) (*params).start_payload.operation_name.as_deref(),
.start_payload
.operation_name
.as_ref()
.map(|s| s.as_str()),
(*params).schema.root_node(), (*params).schema.root_node(),
&(*params).start_payload.variables, &(*params).start_payload.variables,
&(*params).config.context, &(*params).config.context,
@ -575,7 +567,7 @@ where
message: e.to_string(), message: e.to_string(),
}, },
}) })
.to_stream(), .into_stream(),
); );
ConnectionSinkState::Ready { state } ConnectionSinkState::Ready { state }
} }

View file

@ -73,7 +73,7 @@ async fn parse_req<S: ScalarValue>(
} }
_ => return Err(new_response(StatusCode::METHOD_NOT_ALLOWED)), _ => return Err(new_response(StatusCode::METHOD_NOT_ALLOWED)),
} }
.map_err(|e| render_error(e)) .map_err(render_error)
} }
fn parse_get_req<S: ScalarValue>( fn parse_get_req<S: ScalarValue>(

View file

@ -230,7 +230,7 @@ where
.map_err(GraphQLIronError::Url)?; .map_err(GraphQLIronError::Url)?;
let query = parse_url_param(url_query.remove("query"))? let query = parse_url_param(url_query.remove("query"))?
.ok_or_else(|| GraphQLIronError::InvalidData("No query provided"))?; .ok_or(GraphQLIronError::InvalidData("No query provided"))?;
let operation_name = parse_url_param(url_query.remove("operationName"))?; let operation_name = parse_url_param(url_query.remove("operationName"))?;
let variables = parse_variable_param(url_query.remove("variables"))?; let variables = parse_variable_param(url_query.remove("variables"))?;