Skip to content

Commit

Permalink
Make Clippy happy for 1.78 Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed May 2, 2024
1 parent 6ffbb66 commit 875e399
Show file tree
Hide file tree
Showing 22 changed files with 191 additions and 125 deletions.
12 changes: 6 additions & 6 deletions juniper/src/schema/translate/graphql_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ impl<'a, T> SchemaTranslator<'a, graphql_parser::schema::Document<'a, T>>
where
T: Text<'a> + Default,
{
fn translate_schema<S: 'a>(input: &'a SchemaType<S>) -> graphql_parser::schema::Document<'a, T>
fn translate_schema<S>(input: &'a SchemaType<S>) -> graphql_parser::schema::Document<'a, T>
where
S: ScalarValue,
S: ScalarValue + 'a,
{
let mut doc = Document::default();

Expand Down Expand Up @@ -94,9 +94,9 @@ impl GraphQLParserTranslator {
}
}

fn translate_value<'a, S: 'a, T>(input: &'a InputValue<S>) -> ExternalValue<'a, T>
fn translate_value<'a, S, T>(input: &'a InputValue<S>) -> ExternalValue<'a, T>
where
S: ScalarValue,
S: ScalarValue + 'a,
T: Text<'a>,
{
match input {
Expand Down Expand Up @@ -250,9 +250,9 @@ impl GraphQLParserTranslator {
}
}

fn translate_field<'a, S: 'a, T>(input: &'a Field<S>) -> ExternalField<'a, T>
fn translate_field<'a, S, T>(input: &'a Field<S>) -> ExternalField<'a, T>
where
S: ScalarValue,
S: ScalarValue + 'a,
T: Text<'a>,
{
let arguments = input
Expand Down
1 change: 1 addition & 0 deletions juniper/src/schema/translate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{ScalarValue, SchemaType};

#[cfg_attr(not(feature = "schema-language"), allow(dead_code))]
pub trait SchemaTranslator<'a, T> {
fn translate_schema<S: 'a + ScalarValue>(s: &'a SchemaType<S>) -> T;
}
Expand Down
4 changes: 2 additions & 2 deletions juniper/src/validation/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ use crate::{
};

#[doc(hidden)]
pub fn visit_all_rules<'a, S: Debug>(ctx: &mut ValidatorContext<'a, S>, doc: &'a Document<S>)
pub fn visit_all_rules<'a, S>(ctx: &mut ValidatorContext<'a, S>, doc: &'a Document<S>)
where
S: ScalarValue,
S: Debug + ScalarValue,
{
// Some validators are depending on the results of other ones.
// For example, validators checking fragments usually rely on the fact that
Expand Down
12 changes: 6 additions & 6 deletions juniper/src/validation/rules/overlapping_fields_can_be_merged.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,26 @@ impl<K: Eq + Hash + Clone, V> OrderedMap<K, V> {
}
}

fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
fn get<Q>(&self, k: &Q) -> Option<&V>
where
K: Borrow<Q>,
Q: Hash + Eq,
Q: Hash + Eq + ?Sized,
{
self.data.get(k)
}

fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V>
fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
where
K: Borrow<Q>,
Q: Hash + Eq,
Q: Hash + Eq + ?Sized,
{
self.data.get_mut(k)
}

fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool
fn contains_key<Q>(&self, k: &Q) -> bool
where
K: Borrow<Q>,
Q: Hash + Eq,
Q: Hash + Eq + ?Sized,
{
self.data.contains_key(k)
}
Expand Down
14 changes: 0 additions & 14 deletions juniper_codegen/src/common/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,6 @@ mod polyfill {
/// Behaves like [`Result::unwrap()`]: if `self` is [`Ok`] yield the contained value,
/// otherwise abort macro execution.
fn unwrap_or_abort(self) -> Self::Ok;

/// Behaves like [`Result::expect()`]: if `self` is [`Ok`] yield the contained value,
/// otherwise abort macro execution.
///
/// If it aborts then resulting error message will be preceded with the provided `message`.
fn expect_or_abort(self, message: &str) -> Self::Ok;
}

impl<T, E: Into<Diagnostic>> ResultExt for Result<T, E> {
Expand All @@ -356,13 +350,5 @@ mod polyfill {
fn unwrap_or_abort(self) -> T {
self.unwrap_or_else(|e| e.into().abort())
}

fn expect_or_abort(self, message: &str) -> T {
self.unwrap_or_else(|e| {
let mut d = e.into();
d.msg = format!("{message}: {}", d.msg);
d.abort()
})
}
}
}
22 changes: 0 additions & 22 deletions juniper_codegen/src/common/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,6 @@ impl TypeExt for syn::Type {

/// Extension of [`syn::Generics`] providing common function widely used by this crate for parsing.
pub(crate) trait GenericsExt {
/// Removes all default types out of type parameters and const parameters in these
/// [`syn::Generics`].
fn remove_defaults(&mut self);

/// Moves all trait and lifetime bounds of these [`syn::Generics`] to its [`syn::WhereClause`].
fn move_bounds_to_where_clause(&mut self);

Expand All @@ -269,24 +265,6 @@ pub(crate) trait GenericsExt {
}

impl GenericsExt for syn::Generics {
fn remove_defaults(&mut self) {
use syn::GenericParam as P;

for p in &mut self.params {
match p {
P::Type(p) => {
p.eq_token = None;
p.default = None;
}
P::Lifetime(_) => {}
P::Const(p) => {
p.eq_token = None;
p.default = None;
}
}
}
}

fn move_bounds_to_where_clause(&mut self) {
use syn::GenericParam as P;

Expand Down
2 changes: 1 addition & 1 deletion juniper_codegen/src/graphql_interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ impl Definition {

let enum_gens = {
let mut enum_gens = interface_gens.clone();
enum_gens.params = interface_gens_lifetimes.clone();
enum_gens.params.clone_from(&interface_gens_lifetimes);
enum_gens.params.extend(variant_gens_pars.clone());
enum_gens.params.extend(interface_gens_tys.clone());
enum_gens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ error[E0277]: the trait bound `ObjectA: IsInputType<__S>` is not satisfied
<Box<T> as IsInputType<S>>
<juniper::schema::model::DirectiveLocation as IsInputType<__S>>
<Arc<T> as IsInputType<S>>
<Vec<T> as IsInputType<S>>
<TypeKind as IsInputType<__S>>
and $N others

error[E0277]: the trait bound `ObjectA: FromInputValue<__S>` is not satisfied
Expand All @@ -32,7 +32,7 @@ error[E0277]: the trait bound `ObjectA: FromInputValue<__S>` is not satisfied
<Box<T> as FromInputValue<S>>
<juniper::schema::model::DirectiveLocation as FromInputValue<__S>>
<Arc<T> as FromInputValue<S>>
<Vec<T> as FromInputValue<S>>
<TypeKind as FromInputValue<__S>>
and $N others
note: required by a bound in `Registry::<'r, S>::arg`
--> $WORKSPACE/juniper/src/executor/mod.rs
Expand All @@ -57,7 +57,7 @@ error[E0277]: the trait bound `ObjectA: FromInputValue<__S>` is not satisfied
<Box<T> as FromInputValue<S>>
<juniper::schema::model::DirectiveLocation as FromInputValue<__S>>
<Arc<T> as FromInputValue<S>>
<Vec<T> as FromInputValue<S>>
<TypeKind as FromInputValue<__S>>
and $N others
= note: this error originates in the derive macro `GraphQLInputObject` (in Nightly builds, run with -Z macro-backtrace for more info)

Expand All @@ -75,6 +75,6 @@ error[E0277]: the trait bound `ObjectA: ToInputValue<_>` is not satisfied
<Box<T> as ToInputValue<S>>
<juniper::schema::model::DirectiveLocation as ToInputValue<__S>>
<Arc<T> as ToInputValue<S>>
<Vec<T> as ToInputValue<S>>
<TypeKind as ToInputValue<__S>>
and $N others
= note: this error originates in the derive macro `GraphQLInputObject` (in Nightly builds, run with -Z macro-backtrace for more info)
45 changes: 20 additions & 25 deletions tests/codegen/fail/interface/struct/attr_cyclic_impl.stderr
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
error[E0391]: cycle detected when expanding type alias `Node1Value`
--> fail/interface/struct/attr_cyclic_impl.rs:3:46
|
3 | #[graphql_interface(impl = Node2Value, for = Node2Value)]
| ^^^^^^^^^^
|
--> fail/interface/struct/attr_cyclic_impl.rs:3:46
|
3 | #[graphql_interface(impl = Node2Value, for = Node2Value)]
| ^^^^^^^^^^
|
note: ...which requires expanding type alias `Node2Value`...
--> fail/interface/struct/attr_cyclic_impl.rs:8:46
|
8 | #[graphql_interface(impl = Node1Value, for = Node1Value)]
| ^^^^^^^^^^
= note: ...which again requires expanding type alias `Node1Value`, completing the cycle
= note: type aliases cannot be recursive
= help: consider using a struct, enum, or union instead to break the cycle
= help: see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information
note: cycle used when collecting item types in top-level module
--> fail/interface/struct/attr_cyclic_impl.rs:1:1
|
1 | / use juniper::graphql_interface;
2 | |
3 | | #[graphql_interface(impl = Node2Value, for = Node2Value)]
4 | | struct Node1 {
... |
12 | |
13 | | fn main() {}
| |____________^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
--> fail/interface/struct/attr_cyclic_impl.rs:8:46
|
8 | #[graphql_interface(impl = Node1Value, for = Node1Value)]
| ^^^^^^^^^^
= note: ...which again requires expanding type alias `Node1Value`, completing the cycle
= note: type aliases cannot be recursive
= help: consider using a struct, enum, or union instead to break the cycle
= help: see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information
note: cycle used when computing type of `<impl at $DIR/fail/interface/struct/attr_cyclic_impl.rs:3:1: 3:58>`
--> fail/interface/struct/attr_cyclic_impl.rs:3:1
|
3 | #[graphql_interface(impl = Node2Value, for = Node2Value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
= note: this error originates in the attribute macro `graphql_interface` (in Nightly builds, run with -Z macro-backtrace for more info)
15 changes: 5 additions & 10 deletions tests/codegen/fail/interface/struct/derive_cyclic_impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@ note: ...which requires expanding type alias `Node2Value`...
= note: type aliases cannot be recursive
= help: consider using a struct, enum, or union instead to break the cycle
= help: see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information
note: cycle used when collecting item types in top-level module
--> fail/interface/struct/derive_cyclic_impl.rs:1:1
note: cycle used when computing type of `<impl at $DIR/fail/interface/struct/derive_cyclic_impl.rs:3:10: 3:26>`
--> fail/interface/struct/derive_cyclic_impl.rs:3:10
|
1 | / use juniper::GraphQLInterface;
2 | |
3 | | #[derive(GraphQLInterface)]
4 | | #[graphql(impl = Node2Value, for = Node2Value)]
... |
14 | |
15 | | fn main() {}
| |____________^
3 | #[derive(GraphQLInterface)]
| ^^^^^^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
= note: this error originates in the derive macro `GraphQLInterface` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ error[E0277]: the trait bound `ObjA: IsInputType<__S>` is not satisfied
<Box<T> as IsInputType<S>>
<juniper::schema::model::DirectiveLocation as IsInputType<__S>>
<Arc<T> as IsInputType<S>>
<Vec<T> as IsInputType<S>>
<TypeKind as IsInputType<__S>>
<Vec<T> as IsInputType<S>>
and $N others

error[E0277]: the trait bound `ObjA: FromInputValue<__S>` is not satisfied
Expand All @@ -31,8 +31,8 @@ error[E0277]: the trait bound `ObjA: FromInputValue<__S>` is not satisfied
<Box<T> as FromInputValue<S>>
<juniper::schema::model::DirectiveLocation as FromInputValue<__S>>
<Arc<T> as FromInputValue<S>>
<Vec<T> as FromInputValue<S>>
<TypeKind as FromInputValue<__S>>
<Vec<T> as FromInputValue<S>>
and $N others
note: required by a bound in `Registry::<'r, S>::arg`
--> $WORKSPACE/juniper/src/executor/mod.rs
Expand Down
45 changes: 20 additions & 25 deletions tests/codegen/fail/interface/trait/cyclic_impl.stderr
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
error[E0391]: cycle detected when expanding type alias `Node1Value`
--> fail/interface/trait/cyclic_impl.rs:3:46
|
3 | #[graphql_interface(impl = Node2Value, for = Node2Value)]
| ^^^^^^^^^^
|
--> fail/interface/trait/cyclic_impl.rs:3:46
|
3 | #[graphql_interface(impl = Node2Value, for = Node2Value)]
| ^^^^^^^^^^
|
note: ...which requires expanding type alias `Node2Value`...
--> fail/interface/trait/cyclic_impl.rs:8:46
|
8 | #[graphql_interface(impl = Node1Value, for = Node1Value)]
| ^^^^^^^^^^
= note: ...which again requires expanding type alias `Node1Value`, completing the cycle
= note: type aliases cannot be recursive
= help: consider using a struct, enum, or union instead to break the cycle
= help: see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information
note: cycle used when collecting item types in top-level module
--> fail/interface/trait/cyclic_impl.rs:1:1
|
1 | / use juniper::graphql_interface;
2 | |
3 | | #[graphql_interface(impl = Node2Value, for = Node2Value)]
4 | | trait Node1 {
... |
12 | |
13 | | fn main() {}
| |____________^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
--> fail/interface/trait/cyclic_impl.rs:8:46
|
8 | #[graphql_interface(impl = Node1Value, for = Node1Value)]
| ^^^^^^^^^^
= note: ...which again requires expanding type alias `Node1Value`, completing the cycle
= note: type aliases cannot be recursive
= help: consider using a struct, enum, or union instead to break the cycle
= help: see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information
note: cycle used when computing type of `<impl at $DIR/fail/interface/trait/cyclic_impl.rs:3:1: 3:58>`
--> fail/interface/trait/cyclic_impl.rs:3:1
|
3 | #[graphql_interface(impl = Node2Value, for = Node2Value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
= note: this error originates in the attribute macro `graphql_interface` (in Nightly builds, run with -Z macro-backtrace for more info)
16 changes: 12 additions & 4 deletions tests/codegen/fail/object/argument_non_input_type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ error[E0277]: the trait bound `ObjA: IsInputType<__S>` is not satisfied
<Box<T> as IsInputType<S>>
<juniper::schema::model::DirectiveLocation as IsInputType<__S>>
<Arc<T> as IsInputType<S>>
<Vec<T> as IsInputType<S>>
<TypeKind as IsInputType<__S>>
<Vec<T> as IsInputType<S>>
and $N others

error[E0277]: the trait bound `ObjA: FromInputValue<__S>` is not satisfied
Expand All @@ -31,8 +31,8 @@ error[E0277]: the trait bound `ObjA: FromInputValue<__S>` is not satisfied
<Box<T> as FromInputValue<S>>
<juniper::schema::model::DirectiveLocation as FromInputValue<__S>>
<Arc<T> as FromInputValue<S>>
<Vec<T> as FromInputValue<S>>
<TypeKind as FromInputValue<__S>>
<Vec<T> as FromInputValue<S>>
and $N others
note: required by a bound in `Registry::<'r, S>::arg`
--> $WORKSPACE/juniper/src/executor/mod.rs
Expand All @@ -56,8 +56,8 @@ error[E0277]: the trait bound `ObjA: FromInputValue<__S>` is not satisfied
<Box<T> as FromInputValue<S>>
<juniper::schema::model::DirectiveLocation as FromInputValue<__S>>
<Arc<T> as FromInputValue<S>>
<Vec<T> as FromInputValue<S>>
<TypeKind as FromInputValue<__S>>
<Vec<T> as FromInputValue<S>>
and $N others
= note: this error originates in the attribute macro `graphql_object` (in Nightly builds, run with -Z macro-backtrace for more info)

Expand All @@ -74,6 +74,14 @@ error[E0277]: the trait bound `ObjA: FromInputValue<__S>` is not satisfied
<Box<T> as FromInputValue<S>>
<juniper::schema::model::DirectiveLocation as FromInputValue<__S>>
<Arc<T> as FromInputValue<S>>
<Vec<T> as FromInputValue<S>>
<TypeKind as FromInputValue<__S>>
<Vec<T> as FromInputValue<S>>
and $N others

warning: unused variable: `obj`
--> fail/object/argument_non_input_type.rs:12:18
|
12 | fn id(&self, obj: ObjA) -> &str {
| ^^^ help: if this is intentional, prefix it with an underscore: `_obj`
|
= note: `#[warn(unused_variables)]` on by default
Loading

0 comments on commit 875e399

Please sign in to comment.