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(|| {
Response::builder()
.header("content-type", "text/html")
.body(format!(
"<html><h1>juniper_warp</h1><div>visit <a href=\"/graphiql\">/graphiql</a></html>"
))
.body(
"<html><h1>juniper_warp</h1><div>visit <a href=\"/graphiql\">/graphiql</a></html>",
)
});
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.
pub fn is_non_null(&self) -> bool {
match *self {
Type::NonNullNamed(_) | Type::NonNullList(_) => true,
_ => false,
}
matches!(*self, Type::NonNullNamed(_) | Type::NonNullList(_))
}
}
@ -328,18 +325,12 @@ where
/// Does the value represent null?
pub fn is_null(&self) -> bool {
match *self {
InputValue::Null => true,
_ => false,
}
matches!(*self, InputValue::Null)
}
/// Does the value represent a variable?
pub fn is_variable(&self) -> bool {
match *self {
InputValue::Variable(_) => true,
_ => false,
}
matches!(*self, InputValue::Variable(_))
}
/// 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 {
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 {
is_name_start(c) || (c >= '0' && c <= '9')
is_name_start(c) || ('0'..='9').contains(&c)
}
fn is_number_start(c: char) -> bool {
c == '-' || (c >= '0' && c <= '9')
c == '-' || ('0'..='9').contains(&c)
}
impl fmt::Display for LexerError {

View file

@ -348,40 +348,28 @@ impl<'a, S> MetaType<'a, S> {
///
/// Objects, interfaces, and unions are composite.
pub fn is_composite(&self) -> bool {
match *self {
MetaType::Object(_) | MetaType::Interface(_) | MetaType::Union(_) => true,
_ => false,
}
matches!(*self, MetaType::Object(_) | MetaType::Interface(_) | MetaType::Union(_))
}
/// Returns true if the type can occur in leaf positions in queries
///
/// Only enums and scalars are leaf types.
pub fn is_leaf(&self) -> bool {
match *self {
MetaType::Enum(_) | MetaType::Scalar(_) => true,
_ => false,
}
matches!(*self, MetaType::Enum(_) | MetaType::Scalar(_))
}
/// Returns true if the type is abstract
///
/// Only interfaces and unions are abstract types.
pub fn is_abstract(&self) -> bool {
match *self {
MetaType::Interface(_) | MetaType::Union(_) => true,
_ => false,
}
matches!(*self, MetaType::Interface(_) | MetaType::Union(_))
}
/// 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.
pub fn is_input(&self) -> bool {
match *self {
MetaType::Scalar(_) | MetaType::Enum(_) | MetaType::InputObject(_) => true,
_ => false,
}
matches!(*self, MetaType::Scalar(_) | MetaType::Enum(_) | MetaType::InputObject(_))
}
/// 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.
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;
}
@ -414,7 +414,7 @@ impl<'a, S> SchemaType<'a, S> {
) -> bool {
self.possible_types(abstract_type)
.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.
@ -483,10 +483,7 @@ impl<'a, S> TypeType<'a, S> {
#[inline]
pub fn is_non_null(&self) -> bool {
match *self {
TypeType::NonNull(_) => true,
_ => false,
}
matches!(*self, TypeType::NonNull(_))
}
}

View file

@ -9,11 +9,11 @@ use std::{
// stabilise (https://github.com/rust-lang/rust/issues/39658).
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 {
c >= '0' && c <= '9'
('0'..='9').contains(&c)
}
#[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.
#[inline]
pub fn is_explicit_null(&self) -> bool {
match self {
Self::ExplicitNull => true,
_ => false,
}
matches!(self, Self::ExplicitNull)
}
/// Returns `true` if the nullable is a `ImplicitNull` value.
#[inline]
pub fn is_implicit_null(&self) -> bool {
match self {
Self::ImplicitNull => true,
_ => false,
}
matches!(self, Self::ImplicitNull)
}
/// Returns `true` if the nullable is a `Some` value.
#[inline]
pub fn is_some(&self) -> bool {
match self {
Self::Some(_) => true,
_ => false,
}
matches!(self, Self::Some(_))
}
/// Returns `true` if the nullable is not a `Some` value.
#[inline]
pub fn is_null(&self) -> bool {
match self {
Self::Some(_) => false,
_ => true,
}
!matches!(self, Self::Some(_))
}
/// Converts from `&mut Nullable<T>` to `Nullable<&mut T>`.

View file

@ -9,7 +9,11 @@ pub fn to_camel_case(s: &'_ str) -> Cow<'_, str> {
// handle '_' to be more friendly with the
// _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('_') {
stripped
} else {
s
}
.split('_')
.enumerate();

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 {
match type_name.and_then(|n| ctx.schema.concrete_type_by_name(n)) {
Some(&MetaType::Object(_)) => true,
_ => false,
}
let meta = type_name.and_then(|n| ctx.schema.concrete_type_by_name(n));
matches!(meta, Some(&MetaType::Object(_)))
}
fn get_referenced_fields_and_fragment_names(

View file

@ -89,10 +89,7 @@ impl<S: ScalarValue> Value<S> {
/// Does this value represent null?
pub fn is_null(&self) -> bool {
match *self {
Self::Null => true,
_ => false,
}
matches!(*self, Self::Null)
}
/// 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) => {
let generic_type_arg =
generic_args.args.iter().find(|generic_type_arg| {
match generic_type_arg {
syn::GenericArgument::Type(_) => true,
_ => false,
}
matches!(generic_type_arg, syn::GenericArgument::Type(_))
});
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> {
/// 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()
}
}
@ -153,7 +153,7 @@ impl<S: Schema, I: Init<S::ScalarValue, S::Context>> ConnectionState<S, I> {
msg: ClientMessage<S::ScalarValue>,
) -> (Self, BoxStream<'static, Reaction<S>>) {
if let ClientMessage::ConnectionTerminate = msg {
return (self, Reaction::EndStream.to_stream());
return (self, Reaction::EndStream.into_stream());
}
match self {
@ -171,7 +171,7 @@ impl<S: Schema, I: Init<S::ScalarValue, S::Context>> ConnectionState<S, I> {
s = s
.chain(
Reaction::ServerMessage(ServerMessage::ConnectionKeepAlive)
.to_stream(),
.into_stream(),
)
.boxed();
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.
let s = s.chain(
Reaction::ServerMessage(ServerMessage::Complete { id })
.to_stream(),
.into_stream(),
);
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.
match juniper::execute(
&params.start_payload.query,
params
.start_payload
.operation_name
.as_ref()
.map(|s| s.as_str()),
params.start_payload.operation_name.as_deref(),
params.schema.root_node(),
&params.start_payload.variables,
&params.config.context,
@ -322,7 +318,7 @@ impl<S: Schema, I: Init<S::ScalarValue, S::Context>> ConnectionState<S, I> {
id: id.clone(),
payload: DataPayload { data, errors },
})
.to_stream();
.into_stream();
}
Err(GraphQLError::IsSubscription) => {}
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.
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 {
juniper::resolve_into_stream(
&(*params).start_payload.query,
(*params)
.start_payload
.operation_name
.as_ref()
.map(|s| s.as_str()),
(*params).start_payload.operation_name.as_deref(),
(*params).schema.root_node(),
&(*params).start_payload.variables,
&(*params).config.context,
@ -575,7 +567,7 @@ where
message: e.to_string(),
},
})
.to_stream(),
.into_stream(),
);
ConnectionSinkState::Ready { state }
}

View file

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

View file

@ -230,7 +230,7 @@ where
.map_err(GraphQLIronError::Url)?;
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 variables = parse_variable_param(url_query.remove("variables"))?;