Skip to content

Commit 70bc9c4

Browse files
committed
Make Clippy almost happy on latest Rust
1 parent dc99ae7 commit 70bc9c4

File tree

21 files changed

+102
-158
lines changed

21 files changed

+102
-158
lines changed

juniper/src/ast.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ pub enum Definition<'a, S> {
146146
}
147147

148148
#[doc(hidden)]
149-
pub type Document<'a, S> = Vec<Definition<'a, S>>;
149+
pub type Document<'a, S> = [Definition<'a, S>];
150+
#[doc(hidden)]
151+
pub type OwnedDocument<'a, S> = Vec<Definition<'a, S>>;
150152

151153
/// Parse an unstructured input value into a Rust data type.
152154
///
@@ -381,7 +383,7 @@ where
381383
///
382384
/// This constructs a new IndexMap that contain references to the keys
383385
/// and values in `self`.
384-
pub fn to_object_value<'a>(&'a self) -> Option<IndexMap<&'a str, &'a Self>> {
386+
pub fn to_object_value(&self) -> Option<IndexMap<&str, &Self>> {
385387
match *self {
386388
InputValue::Object(ref o) => Some(
387389
o.iter()

juniper/src/executor/look_ahead.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,15 +440,15 @@ impl<'a, S> LookAheadMethods<'a, S> for LookAheadSelection<'a, S> {
440440
mod tests {
441441
use super::*;
442442
use crate::{
443-
ast::Document,
443+
ast::{Document, OwnedDocument},
444444
parser::UnlocatedParseResult,
445445
schema::model::SchemaType,
446446
validation::test_harness::{MutationRoot, QueryRoot, SubscriptionRoot},
447447
value::{DefaultScalarValue, ScalarValue},
448448
};
449449
use std::collections::HashMap;
450450

451-
fn parse_document_source<S>(q: &str) -> UnlocatedParseResult<Document<S>>
451+
fn parse_document_source<S>(q: &str) -> UnlocatedParseResult<OwnedDocument<S>>
452452
where
453453
S: ScalarValue,
454454
{

juniper/src/executor/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ where
326326
{
327327
type Type = T;
328328

329+
#[allow(clippy::type_complexity)]
329330
fn into(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, Option<T>)>, S> {
330331
Ok(self.map(|(ctx, v)| (ctx, Some(v))))
331332
}
@@ -353,6 +354,7 @@ where
353354
{
354355
type Type = T;
355356

357+
#[allow(clippy::type_complexity)]
356358
fn into(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, Option<T>)>, S2> {
357359
self.map(|o| o.map(|(ctx, v)| (ctx, Some(v))))
358360
.map_err(FieldError::map_scalar_value)

juniper/src/executor/owned_executor.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,8 @@ where
112112
Executor {
113113
fragments: &self.fragments,
114114
variables: &self.variables,
115-
current_selection_set: if let Some(s) = &self.current_selection_set {
116-
Some(&s[..])
117-
} else {
118-
None
119-
},
120-
parent_selection_set: if let Some(s) = &self.parent_selection_set {
121-
Some(&s[..])
122-
} else {
123-
None
124-
},
115+
current_selection_set: self.current_selection_set.as_deref(),
116+
parent_selection_set: self.parent_selection_set.as_deref(),
125117
current_type: self.current_type.clone(),
126118
schema: self.schema,
127119
context: self.context,

juniper/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ where
319319
SubscriptionT::TypeInfo: Sync,
320320
S: ScalarValue + Send + Sync,
321321
{
322-
let document: crate::ast::Document<'a, S> =
322+
let document: crate::ast::OwnedDocument<'a, S> =
323323
parse_document_source(document_source, &root_node.schema)?;
324324

325325
{

juniper/src/parser/document.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use std::borrow::Cow;
22

33
use crate::ast::{
4-
Arguments, Definition, Directive, Document, Field, Fragment, FragmentSpread, InlineFragment,
5-
InputValue, Operation, OperationType, Selection, Type, VariableDefinition, VariableDefinitions,
4+
Arguments, Definition, Directive, Field, Fragment, FragmentSpread, InlineFragment, InputValue,
5+
Operation, OperationType, OwnedDocument, Selection, Type, VariableDefinition,
6+
VariableDefinitions,
67
};
78

89
use crate::{
@@ -21,7 +22,7 @@ use crate::{
2122
pub fn parse_document_source<'a, 'b, S>(
2223
s: &'a str,
2324
schema: &'b SchemaType<'b, S>,
24-
) -> UnlocatedParseResult<'a, Document<'a, S>>
25+
) -> UnlocatedParseResult<'a, OwnedDocument<'a, S>>
2526
where
2627
S: ScalarValue,
2728
{
@@ -33,7 +34,7 @@ where
3334
fn parse_document<'a, 'b, S>(
3435
parser: &mut Parser<'a>,
3536
schema: &'b SchemaType<'b, S>,
36-
) -> UnlocatedParseResult<'a, Document<'a, S>>
37+
) -> UnlocatedParseResult<'a, OwnedDocument<'a, S>>
3738
where
3839
S: ScalarValue,
3940
{

juniper/src/parser/tests/document.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{
22
ast::{
3-
Arguments, Definition, Document, Field, InputValue, Operation, OperationType, Selection,
3+
Arguments, Definition, Field, InputValue, Operation, OperationType, OwnedDocument,
4+
Selection,
45
},
56
parser::{document::parse_document_source, ParseError, SourcePosition, Spanning, Token},
67
schema::model::SchemaType,
@@ -9,7 +10,7 @@ use crate::{
910
value::{DefaultScalarValue, ScalarValue},
1011
};
1112

12-
fn parse_document<S>(s: &str) -> Document<S>
13+
fn parse_document<S>(s: &str) -> OwnedDocument<S>
1314
where
1415
S: ScalarValue,
1516
{

juniper/src/schema/model.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,10 @@ impl<'a, S> SchemaType<'a, S> {
293293

294294
/// Get the mutation type from the schema.
295295
pub fn mutation_type(&self) -> Option<TypeType<S>> {
296-
if let Some(ref mutation_type_name) = self.mutation_type_name {
297-
Some(
298-
self.type_by_name(mutation_type_name)
299-
.expect("Mutation type does not exist in schema"),
300-
)
301-
} else {
302-
None
303-
}
296+
self.mutation_type_name.as_ref().map(|name| {
297+
self.type_by_name(name)
298+
.expect("Mutation type does not exist in schema")
299+
})
304300
}
305301

306302
/// Get the concrete mutation type from the schema.
@@ -313,14 +309,10 @@ impl<'a, S> SchemaType<'a, S> {
313309

314310
/// Get the subscription type.
315311
pub fn subscription_type(&self) -> Option<TypeType<S>> {
316-
if let Some(ref subscription_type_name) = self.subscription_type_name {
317-
Some(
318-
self.type_by_name(subscription_type_name)
319-
.expect("Subscription type does not exist in schema"),
320-
)
321-
} else {
322-
None
323-
}
312+
self.subscription_type_name.as_ref().map(|name| {
313+
self.type_by_name(name)
314+
.expect("Subscription type does not exist in schema")
315+
})
324316
}
325317

326318
/// Get the concrete subscription type.

juniper/src/types/containers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,16 @@ where
299299
S: ScalarValue + Send + Sync,
300300
{
301301
use futures::stream::{FuturesOrdered, StreamExt as _};
302-
use std::iter::FromIterator;
303302

304303
let stop_on_null = executor
305304
.current_type()
306305
.list_contents()
307306
.expect("Current type is not a list type")
308307
.is_non_null();
309308

310-
let iter = items.map(|it| async move { executor.resolve_into_value_async(info, it).await });
311-
let mut futures = FuturesOrdered::from_iter(iter);
309+
let mut futures = items
310+
.map(|it| async move { executor.resolve_into_value_async(info, it).await })
311+
.collect::<FuturesOrdered<_>>();
312312

313313
let mut values = Vec::with_capacity(futures.len());
314314
while let Some(value) = futures.next().await {

juniper/src/types/pointers.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@ where
9494
T: FromInputValue<S>,
9595
{
9696
fn from_input_value(v: &InputValue<S>) -> Option<Box<T>> {
97-
match <T as FromInputValue<S>>::from_input_value(v) {
98-
Some(v) => Some(Box::new(v)),
99-
None => None,
100-
}
97+
<T as FromInputValue<S>>::from_input_value(v).map(Box::new)
10198
}
10299
}
103100

@@ -289,10 +286,7 @@ where
289286
T: FromInputValue<S>,
290287
{
291288
fn from_input_value(v: &InputValue<S>) -> Option<Arc<T>> {
292-
match <T as FromInputValue<S>>::from_input_value(v) {
293-
Some(v) => Some(Arc::new(v)),
294-
None => None,
295-
}
289+
<T as FromInputValue<S>>::from_input_value(v).map(Arc::new)
296290
}
297291
}
298292

juniper/src/validation/multi_visitor.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,11 @@ where
230230
self.1.exit_list_value(ctx, l);
231231
}
232232

233-
fn enter_object_value(
234-
&mut self,
235-
ctx: &mut ValidatorContext<'a, S>,
236-
o: Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>,
237-
) {
233+
fn enter_object_value(&mut self, ctx: &mut ValidatorContext<'a, S>, o: SpannedObject<'a, S>) {
238234
self.0.enter_object_value(ctx, o);
239235
self.1.enter_object_value(ctx, o);
240236
}
241-
fn exit_object_value(
242-
&mut self,
243-
ctx: &mut ValidatorContext<'a, S>,
244-
o: Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>,
245-
) {
237+
fn exit_object_value(&mut self, ctx: &mut ValidatorContext<'a, S>, o: SpannedObject<'a, S>) {
246238
self.0.exit_object_value(ctx, o);
247239
self.1.exit_object_value(ctx, o);
248240
}
@@ -264,3 +256,5 @@ where
264256
self.1.exit_object_field(ctx, f);
265257
}
266258
}
259+
260+
type SpannedObject<'a, S> = Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>;

juniper/src/validation/rules/unique_input_field_names.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,11 @@ impl<'a, S> Visitor<'a, S> for UniqueInputFieldNames<'a>
2121
where
2222
S: ScalarValue,
2323
{
24-
fn enter_object_value(
25-
&mut self,
26-
_: &mut ValidatorContext<'a, S>,
27-
_: Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>,
28-
) {
24+
fn enter_object_value(&mut self, _: &mut ValidatorContext<'a, S>, _: SpannedObject<'a, S>) {
2925
self.known_name_stack.push(HashMap::new());
3026
}
3127

32-
fn exit_object_value(
33-
&mut self,
34-
_: &mut ValidatorContext<'a, S>,
35-
_: Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>,
36-
) {
28+
fn exit_object_value(&mut self, _: &mut ValidatorContext<'a, S>, _: SpannedObject<'a, S>) {
3729
self.known_name_stack.pop();
3830
}
3931

@@ -58,6 +50,8 @@ where
5850
}
5951
}
6052

53+
type SpannedObject<'a, S> = Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>;
54+
6155
fn error_message(field_name: &str) -> String {
6256
format!("There can only be one input field named \"{}\"", field_name)
6357
}

juniper/src/validation/test_harness.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,9 @@ where
865865
let mut ctx = ValidatorContext::new(unsafe { ::std::mem::transmute(&root.schema) }, &doc);
866866

867867
let mut mv = MultiVisitorNil.with(factory());
868-
visit(&mut mv, &mut ctx, unsafe { ::std::mem::transmute(&doc) });
868+
visit(&mut mv, &mut ctx, unsafe {
869+
::std::mem::transmute(doc.as_slice())
870+
});
869871

870872
ctx.into_errors()
871873
}

juniper/src/validation/traits.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,8 @@ where
128128
) {
129129
}
130130

131-
fn enter_object_value(
132-
&mut self,
133-
_: &mut ValidatorContext<'a, S>,
134-
_: Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>,
135-
) {
136-
}
137-
fn exit_object_value(
138-
&mut self,
139-
_: &mut ValidatorContext<'a, S>,
140-
_: Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>,
141-
) {
142-
}
131+
fn enter_object_value(&mut self, _: &mut ValidatorContext<'a, S>, _: SpannedObject<'a, S>) {}
132+
fn exit_object_value(&mut self, _: &mut ValidatorContext<'a, S>, _: SpannedObject<'a, S>) {}
143133

144134
fn enter_object_field(
145135
&mut self,
@@ -154,3 +144,5 @@ where
154144
) {
155145
}
156146
}
147+
148+
type SpannedObject<'a, S> = Spanning<&'a Vec<(Spanning<String>, Spanning<InputValue<S>>)>>;

juniper_actix/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ where
7373
operation_name,
7474
variables,
7575
} = get_req;
76-
let variables = match variables {
77-
Some(variables) => Some(serde_json::from_str(&variables).unwrap()),
78-
None => None,
79-
};
76+
let variables = variables.map(|s| serde_json::from_str(&s).unwrap());
8077
Self::new(query, operation_name, variables)
8178
}
8279
}

0 commit comments

Comments
 (0)