Skip to content

Commit 438d56a

Browse files
committed
Fix cargo clippy warnings
1 parent a7d843e commit 438d56a

File tree

9 files changed

+28
-26
lines changed

9 files changed

+28
-26
lines changed

juniper/src/executor/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,20 +230,20 @@ impl<'a, T: GraphQLType, C> IntoResolvable<'a, Option<T>, C>
230230
/// Conversion trait for context types
231231
///
232232
/// Used to support different context types for different parts of an
233-
/// application. By making each GraphQL type only aware of as much
233+
/// application. By making each `GraphQL` type only aware of as much
234234
/// context as it needs to, isolation and robustness can be
235235
/// improved. Implement this trait if you have contexts that can
236236
/// generally be converted between each other.
237237
///
238238
/// The empty tuple `()` can be converted into from any context type,
239-
/// making it suitable for GraphQL that don't need _any_ context to
239+
/// making it suitable for `GraphQL` that don't need _any_ context to
240240
/// work, e.g. scalars or enums.
241241
pub trait FromContext<T> {
242242
/// Perform the conversion
243243
fn from(value: &T) -> &Self;
244244
}
245245

246-
/// Marker trait for types that can act as context objects for GraphQL types.
246+
/// Marker trait for types that can act as context objects for `GraphQL` types.
247247
pub trait Context {}
248248

249249
impl<'a, C: Context> Context for &'a C {}

juniper/src/integrations/serde.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ impl<'de> de::Deserialize<'de> for InputValue {
7676
where
7777
E: de::Error,
7878
{
79-
if value >= i32::min_value() as i64 && value <= i32::max_value() as i64 {
80-
Ok(InputValue::int(value as i32))
79+
if value >= i64::from(i32::min_value()) && value <= i64::from(i32::max_value()) {
80+
Ok(InputValue::int(i32::from(value)))
8181
} else {
8282
Err(E::custom(format!("integer out of range")))
8383
}
@@ -87,8 +87,8 @@ impl<'de> de::Deserialize<'de> for InputValue {
8787
where
8888
E: de::Error,
8989
{
90-
if value <= i32::max_value() as u64 {
91-
self.visit_i64(value as i64)
90+
if value <= u64::from(i32::max_value()) {
91+
self.visit_i64(i64::from(value))
9292
} else {
9393
Err(E::custom(format!("integer out of range")))
9494
}
@@ -155,7 +155,7 @@ impl ser::Serialize for InputValue {
155155
{
156156
match *self {
157157
InputValue::Null | InputValue::Variable(_) => serializer.serialize_unit(),
158-
InputValue::Int(v) => serializer.serialize_i64(v as i64),
158+
InputValue::Int(v) => serializer.serialize_i64(i64::from(v)),
159159
InputValue::Float(v) => serializer.serialize_f64(v),
160160
InputValue::String(ref v) | InputValue::Enum(ref v) => serializer.serialize_str(v),
161161
InputValue::Boolean(v) => serializer.serialize_bool(v),
@@ -238,7 +238,7 @@ impl ser::Serialize for Value {
238238
{
239239
match *self {
240240
Value::Null => serializer.serialize_unit(),
241-
Value::Int(v) => serializer.serialize_i64(v as i64),
241+
Value::Int(v) => serializer.serialize_i64(i64::from(v)),
242242
Value::Float(v) => serializer.serialize_f64(v),
243243
Value::String(ref v) => serializer.serialize_str(v),
244244
Value::Boolean(v) => serializer.serialize_bool(v),

juniper/src/macros/scalar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,6 @@ macro_rules! graphql_scalar {
151151
// Entry point
152152
// RustName { ... }
153153
( $name:ty { $( $items:tt )* }) => {
154-
graphql_scalar!( @parse, ( $name, (stringify!($name)), None ), ( None, None ), $($items)* );
154+
graphql_scalar!( @parse, ( $name, stringify!($name), None ), ( None, None ), $($items)* );
155155
};
156156
}

juniper/src/parser/lexer.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl<'a> Lexer<'a> {
390390
}
391391

392392
let mantissa = frac_part
393-
.map(|f| f as f64)
393+
.map(|f| f64::from(f))
394394
.map(|frac| {
395395
if frac > 0f64 {
396396
frac / 10f64.powf(frac.log10().floor() + 1f64)
@@ -400,16 +400,18 @@ impl<'a> Lexer<'a> {
400400
})
401401
.map(|m| if int_part < 0 { -m } else { m });
402402

403-
let exp = exp_part.map(|e| e as f64).map(|e| 10f64.powf(e));
403+
let exp = exp_part.map(|e| f64::from(e)).map(|e| 10f64.powf(e));
404404

405405
Ok(Spanning::start_end(
406406
&start_pos,
407407
&self.position,
408408
match (mantissa, exp) {
409409
(None, None) => Token::Int(int_part),
410-
(None, Some(exp)) => Token::Float((int_part as f64) * exp),
411-
(Some(mantissa), None) => Token::Float((int_part as f64) + mantissa),
412-
(Some(mantissa), Some(exp)) => Token::Float(((int_part as f64) + mantissa) * exp),
410+
(None, Some(exp)) => Token::Float((f64::from(int_part)) * exp),
411+
(Some(mantissa), None) => Token::Float((f64::from(int_part)) + mantissa),
412+
(Some(mantissa), Some(exp)) => {
413+
Token::Float(((f64::from(int_part)) + mantissa) * exp)
414+
}
413415
},
414416
))
415417
}

juniper/src/schema/meta.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Types used to describe a GraphQL schema
1+
//! Types used to describe a `GraphQL` schema
22
33
use std::borrow::Cow;
44
use std::fmt;

juniper/src/types/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ where
374374

375375
let sub_exec = executor.field_sub_executor(
376376
response_name,
377-
&f.name.item,
377+
f.name.item,
378378
start_pos.clone(),
379379
f.selection_set.as_ref().map(|v| &v[..]),
380380
);

juniper/src/types/scalars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ graphql_scalar!(f64 as "Float" {
113113

114114
from_input_value(v: &InputValue) -> Option<f64> {
115115
match *v {
116-
InputValue::Int(i) => Some(i as f64),
116+
InputValue::Int(i) => Some(f64::from(i)),
117117
InputValue::Float(f) => Some(f),
118118
_ => None,
119119
}

juniper_iron/examples/iron_server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn main() {
3737
chain.link_before(logger_before);
3838
chain.link_after(logger_after);
3939

40-
let host = env::var("LISTEN").unwrap_or("0.0.0.0:8080".to_owned());
40+
let host = env::var("LISTEN").unwrap_or_else(|_| "0.0.0.0:8080".to_owned());
4141
println!("GraphQL server started on {}", host);
4242
Iron::new(chain).http(host.as_str()).unwrap();
4343
}

juniper_iron/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ use serde_json::error::Error as SerdeError;
125125
use juniper::{GraphQLType, InputValue, RootNode};
126126
use juniper::http;
127127

128-
/// Handler that executes GraphQL queries in the given schema
128+
/// Handler that executes `GraphQL` queries in the given schema
129129
///
130130
/// The handler responds to GET requests and POST requests only. In GET
131131
/// requests, the query should be supplied in the `query` URL parameter, e.g.
@@ -146,7 +146,7 @@ where
146146
root_node: RootNode<'a, Query, Mutation>,
147147
}
148148

149-
/// Handler that renders GraphiQL - a graphical query editor interface
149+
/// Handler that renders `GraphiQL` - a graphical query editor interface
150150
pub struct GraphiQLHandler {
151151
graphql_url: String,
152152
}
@@ -201,7 +201,7 @@ where
201201

202202
fn handle_get(&self, req: &mut Request) -> IronResult<http::GraphQLRequest> {
203203
let url_query_string = req.get_mut::<UrlEncodedQuery>()
204-
.map_err(|e| GraphQLIronError::Url(e))?;
204+
.map_err(GraphQLIronError::Url)?;
205205

206206
let input_query = parse_url_param(url_query_string.remove("query"))?
207207
.ok_or_else(|| GraphQLIronError::InvalidData("No query provided"))?;
@@ -221,7 +221,7 @@ where
221221

222222
Ok(
223223
serde_json::from_str::<http::GraphQLRequest>(request_payload.as_str())
224-
.map_err(|err| GraphQLIronError::Serde(err))?,
224+
.map_err(GraphQLIronError::Serde)?,
225225
)
226226
}
227227

@@ -265,7 +265,7 @@ where
265265
let graphql_request = match req.method {
266266
method::Get => self.handle_get(&mut req)?,
267267
method::Post => self.handle_post(&mut req)?,
268-
_ => return Ok(Response::with((status::MethodNotAllowed))),
268+
_ => return Ok(Response::with(status::MethodNotAllowed)),
269269
};
270270

271271
self.execute(&context, graphql_request)
@@ -296,7 +296,7 @@ impl fmt::Display for GraphQLIronError {
296296
match *self {
297297
GraphQLIronError::Serde(ref err) => fmt::Display::fmt(err, &mut f),
298298
GraphQLIronError::Url(ref err) => fmt::Display::fmt(err, &mut f),
299-
GraphQLIronError::InvalidData(ref err) => fmt::Display::fmt(err, &mut f),
299+
GraphQLIronError::InvalidData(err) => fmt::Display::fmt(err, &mut f),
300300
}
301301
}
302302
}
@@ -306,7 +306,7 @@ impl Error for GraphQLIronError {
306306
match *self {
307307
GraphQLIronError::Serde(ref err) => err.description(),
308308
GraphQLIronError::Url(ref err) => err.description(),
309-
GraphQLIronError::InvalidData(ref err) => err,
309+
GraphQLIronError::InvalidData(err) => err,
310310
}
311311
}
312312

0 commit comments

Comments
 (0)