From 9ffa286e3506926627cd47a5a925d33ce9fc1599 Mon Sep 17 00:00:00 2001 From: Ivan Petkov Date: Sun, 9 Nov 2025 09:39:56 -0800 Subject: [PATCH 1/2] Fix clippy warnings --- derive/src/args.rs | 9 +---- derive/src/complex_object.rs | 12 +++--- derive/src/directive.rs | 10 ++--- derive/src/object.rs | 12 +++--- derive/src/type_directive.rs | 10 ++--- derive/src/union.rs | 13 +++---- derive/src/utils.rs | 64 +++++++++++++++---------------- integrations/axum/src/response.rs | 13 +++---- src/context.rs | 4 +- src/dynamic/field.rs | 6 +-- src/dynamic/subscription.rs | 2 +- src/dynamic/union.rs | 2 +- src/extensions/mod.rs | 2 +- src/registry/mod.rs | 2 +- src/types/maybe_undefined.rs | 9 +---- value/src/deserializer.rs | 2 +- value/src/lib.rs | 18 ++------- value/src/value_serde.rs | 11 +++--- 18 files changed, 87 insertions(+), 114 deletions(-) diff --git a/derive/src/args.rs b/derive/src/args.rs index 3e3e3a39..1bd4d4a0 100644 --- a/derive/src/args.rs +++ b/derive/src/args.rs @@ -913,19 +913,14 @@ pub struct Description { pub internal: bool, } -#[derive(Debug)] +#[derive(Debug, Default)] pub enum NewTypeName { New(String), Rust, + #[default] Original, } -impl Default for NewTypeName { - fn default() -> Self { - Self::Original - } -} - impl FromMeta for NewTypeName { fn from_word() -> darling::Result { Ok(Self::Rust) diff --git a/derive/src/complex_object.rs b/derive/src/complex_object.rs index 12805ccb..a1886d0d 100644 --- a/derive/src/complex_object.rs +++ b/derive/src/complex_object.rs @@ -60,13 +60,11 @@ pub fn generate( .iter() .nth(1) .map(|x| { - if let FnArg::Typed(pat) = x { - if let Type::Reference(TypeReference { elem, .. }) = &*pat.ty { - if let Type::Path(path) = elem.as_ref() { - return path.path.segments.last().unwrap().ident - != "Context"; - } - } + if let FnArg::Typed(pat) = x + && let Type::Reference(TypeReference { elem, .. }) = &*pat.ty + && let Type::Path(path) = elem.as_ref() + { + return path.path.segments.last().unwrap().ident != "Context"; }; true }) diff --git a/derive/src/directive.rs b/derive/src/directive.rs index 80f6e705..97d1d68e 100644 --- a/derive/src/directive.rs +++ b/derive/src/directive.rs @@ -39,11 +39,11 @@ pub fn generate( for arg in item_fn.sig.inputs.iter_mut() { let mut arg_info = None; - if let FnArg::Typed(pat) = arg { - if let Pat::Ident(ident) = &*pat.pat { - arg_info = Some((ident.clone(), pat.ty.clone(), pat.attrs.clone())); - remove_graphql_attrs(&mut pat.attrs); - } + if let FnArg::Typed(pat) = arg + && let Pat::Ident(ident) = &*pat.pat + { + arg_info = Some((ident.clone(), pat.ty.clone(), pat.attrs.clone())); + remove_graphql_attrs(&mut pat.attrs); } let (arg_ident, arg_ty, arg_attrs) = match arg_info { diff --git a/derive/src/object.rs b/derive/src/object.rs index 6d20784f..0f0b6a84 100644 --- a/derive/src/object.rs +++ b/derive/src/object.rs @@ -104,13 +104,11 @@ pub fn generate( .iter() .nth(1) .map(|x| { - if let FnArg::Typed(pat) = x { - if let Type::Reference(TypeReference { elem, .. }) = &*pat.ty { - if let Type::Path(path) = elem.as_ref() { - return path.path.segments.last().unwrap().ident - != "Context"; - } - } + if let FnArg::Typed(pat) = x + && let Type::Reference(TypeReference { elem, .. }) = &*pat.ty + && let Type::Path(path) = elem.as_ref() + { + return path.path.segments.last().unwrap().ident != "Context"; }; true }) diff --git a/derive/src/type_directive.rs b/derive/src/type_directive.rs index c479c130..1896a74e 100644 --- a/derive/src/type_directive.rs +++ b/derive/src/type_directive.rs @@ -44,11 +44,11 @@ pub fn generate( for arg in item_fn.sig.inputs.iter_mut() { let mut arg_info = None; - if let FnArg::Typed(pat) = arg { - if let Pat::Ident(ident) = &*pat.pat { - arg_info = Some((ident.clone(), pat.ty.clone(), pat.attrs.clone())); - remove_graphql_attrs(&mut pat.attrs); - } + if let FnArg::Typed(pat) = arg + && let Pat::Ident(ident) = &*pat.pat + { + arg_info = Some((ident.clone(), pat.ty.clone(), pat.attrs.clone())); + remove_graphql_attrs(&mut pat.attrs); } let (arg_ident, arg_ty, arg_attrs) = match arg_info { diff --git a/derive/src/union.rs b/derive/src/union.rs index 192367af..db3040ea 100644 --- a/derive/src/union.rs +++ b/derive/src/union.rs @@ -325,14 +325,13 @@ pub fn generate(union_args: &args::Union) -> GeneratorResult { // Check if the type is a generic parameter which we should // convert to a concrete type - if let syn::Type::Path(ty_path) = ty { - if let Some(idx) = type_params.iter().position(|p| { + if let syn::Type::Path(ty_path) = ty + && let Some(idx) = type_params.iter().position(|p| { p.ident == ty_path.path.segments[0].ident - }) { - let param = ¶ms[idx]; - *ty = syn::parse2::(quote!(#param)) - .unwrap(); - } + }) + { + let param = ¶ms[idx]; + *ty = syn::parse2::(quote!(#param)).unwrap(); } } } diff --git a/derive/src/utils.rs b/derive/src/utils.rs index 01983997..701d45f6 100644 --- a/derive/src/utils.rs +++ b/derive/src/utils.rs @@ -63,28 +63,28 @@ pub fn get_rustdoc(attrs: &[Attribute]) -> GeneratorResult> let mut full_docs: Vec = vec![]; let mut combined_docs_literal = String::new(); for attr in attrs { - if let Meta::NameValue(nv) = &attr.meta { - if nv.path.is_ident("doc") { - match &nv.value { - Expr::Lit(ExprLit { - lit: Lit::Str(doc), .. - }) => { - let doc = doc.value(); - let doc_str = doc.trim(); + if let Meta::NameValue(nv) = &attr.meta + && nv.path.is_ident("doc") + { + match &nv.value { + Expr::Lit(ExprLit { + lit: Lit::Str(doc), .. + }) => { + let doc = doc.value(); + let doc_str = doc.trim(); + combined_docs_literal += "\n"; + combined_docs_literal += doc_str; + } + Expr::Macro(include_macro) => { + if !combined_docs_literal.is_empty() { combined_docs_literal += "\n"; - combined_docs_literal += doc_str; - } - Expr::Macro(include_macro) => { - if !combined_docs_literal.is_empty() { - combined_docs_literal += "\n"; - let lit = LitStr::new(&combined_docs_literal, Span::call_site()); - full_docs.push(quote!( #lit )); - combined_docs_literal.clear(); - } - full_docs.push(quote!( #include_macro )); + let lit = LitStr::new(&combined_docs_literal, Span::call_site()); + full_docs.push(quote!( #lit )); + combined_docs_literal.clear(); } - _ => (), + full_docs.push(quote!( #include_macro )); } + _ => (), } } } @@ -226,10 +226,10 @@ pub fn parse_complexity_expr(expr: Expr) -> GeneratorResult<(HashSet, Ex impl<'a> Visit<'a> for VisitComplexityExpr { fn visit_expr_path(&mut self, i: &'a ExprPath) { - if let Some(ident) = i.path.get_ident() { - if ident != "child_complexity" { - self.variables.insert(ident.to_string()); - } + if let Some(ident) = i.path.get_ident() + && ident != "child_complexity" + { + self.variables.insert(ident.to_string()); } } } @@ -355,17 +355,17 @@ pub fn gen_directive_calls( } fn extract_directive_call_path(directive: &Expr) -> Option { - if let Expr::Call(expr) = directive { - if let Expr::Path(ref expr) = *expr.func { - let mut path = expr.path.clone(); - if path.segments.pop()?.value().ident != "apply" { - return None; - } + if let Expr::Call(expr) = directive + && let Expr::Path(ref expr) = *expr.func + { + let mut path = expr.path.clone(); + if path.segments.pop()?.value().ident != "apply" { + return None; + } - path.segments.pop_punct()?; + path.segments.pop_punct()?; - return Some(path); - } + return Some(path); } None diff --git a/integrations/axum/src/response.rs b/integrations/axum/src/response.rs index fade3c47..c8e4425a 100644 --- a/integrations/axum/src/response.rs +++ b/integrations/axum/src/response.rs @@ -31,13 +31,12 @@ impl IntoResponse for GraphQLResponse { http::header::CONTENT_TYPE, HeaderValue::from_static("application/graphql-response+json"), ); - if self.0.is_ok() { - if let Some(cache_control) = self.0.cache_control().value() { - if let Ok(value) = HeaderValue::from_str(&cache_control) { - resp.headers_mut() - .insert(http::header::CACHE_CONTROL, value); - } - } + if self.0.is_ok() + && let Some(cache_control) = self.0.cache_control().value() + && let Ok(value) = HeaderValue::from_str(&cache_control) + { + resp.headers_mut() + .insert(http::header::CACHE_CONTROL, value); } resp.headers_mut().extend(self.0.http_headers()); diff --git a/src/context.rs b/src/context.rs index 1a92315f..27e3896c 100644 --- a/src/context.rs +++ b/src/context.rs @@ -683,7 +683,7 @@ impl<'a> ContextBase<'a, &'a Positioned> { /// } /// } /// ``` - pub fn look_ahead(&self) -> Lookahead { + pub fn look_ahead(&self) -> Lookahead<'_> { Lookahead::new(&self.query_env.fragments, &self.item.node, self) } @@ -728,7 +728,7 @@ impl<'a> ContextBase<'a, &'a Positioned> { /// ); /// # }); /// ``` - pub fn field(&self) -> SelectionField { + pub fn field(&self) -> SelectionField<'_> { SelectionField { fragments: &self.query_env.fragments, field: &self.item.node, diff --git a/src/dynamic/field.rs b/src/dynamic/field.rs index b6f592a7..0fb1ee04 100644 --- a/src/dynamic/field.rs +++ b/src/dynamic/field.rs @@ -224,7 +224,7 @@ impl<'a> FieldValue<'a> { /// If the FieldValue is a list, returns the associated /// vector. Returns `None` otherwise. #[inline] - pub fn as_list(&self) -> Option<&[FieldValue]> { + pub fn as_list(&self) -> Option<&[FieldValue<'_>]> { match &self.0 { FieldValueInner::List(values) => Some(values), _ => None, @@ -233,7 +233,7 @@ impl<'a> FieldValue<'a> { /// Like `as_list`, but returns `Result`. #[inline] - pub fn try_to_list(&self) -> Result<&[FieldValue]> { + pub fn try_to_list(&self) -> Result<&[FieldValue<'_>]> { self.as_list() .ok_or_else(|| Error::new(format!("internal: \"{:?}\" not a List", self))) } @@ -314,7 +314,7 @@ impl<'a> FieldFuture<'a> { } pub(crate) type BoxResolverFn = - Box<(dyn for<'a> Fn(ResolverContext<'a>) -> FieldFuture<'a> + Send + Sync)>; + Box Fn(ResolverContext<'a>) -> FieldFuture<'a> + Send + Sync>; /// A GraphQL field pub struct Field { diff --git a/src/dynamic/subscription.rs b/src/dynamic/subscription.rs index 00a8ebb6..6689ffe3 100644 --- a/src/dynamic/subscription.rs +++ b/src/dynamic/subscription.rs @@ -42,7 +42,7 @@ impl<'a> SubscriptionFieldFuture<'a> { } type BoxResolverFn = - Arc<(dyn for<'a> Fn(ResolverContext<'a>) -> SubscriptionFieldFuture<'a> + Send + Sync)>; + Arc Fn(ResolverContext<'a>) -> SubscriptionFieldFuture<'a> + Send + Sync>; /// A GraphQL subscription field pub struct SubscriptionField { diff --git a/src/dynamic/union.rs b/src/dynamic/union.rs index 70e56706..ef47b1fc 100644 --- a/src/dynamic/union.rs +++ b/src/dynamic/union.rs @@ -281,7 +281,7 @@ mod tests { } impl Animal { - fn to_field_value(&self) -> FieldValue { + fn to_field_value(&self) -> FieldValue<'_> { match self { Animal::Dog(dog) => FieldValue::borrowed_any(dog).with_type("Dog"), Animal::Cat(cat) => FieldValue::borrowed_any(cat).with_type("Cat"), diff --git a/src/extensions/mod.rs b/src/extensions/mod.rs index 6baa6796..b23374e2 100644 --- a/src/extensions/mod.rs +++ b/src/extensions/mod.rs @@ -490,7 +490,7 @@ impl Extensions { } #[inline] - fn create_context(&self) -> ExtensionContext { + fn create_context(&self) -> ExtensionContext<'_> { ExtensionContext { schema_env: &self.schema_env, session_data: &self.session_data, diff --git a/src/registry/mod.rs b/src/registry/mod.rs index 240f391b..901c9324 100644 --- a/src/registry/mod.rs +++ b/src/registry/mod.rs @@ -46,7 +46,7 @@ impl Display for MetaTypeName<'_> { impl MetaTypeName<'_> { #[inline] - pub fn create(type_name: &str) -> MetaTypeName { + pub fn create(type_name: &str) -> MetaTypeName<'_> { if let Some(type_name) = type_name.strip_suffix('!') { MetaTypeName::NonNull(type_name) } else if let Some(type_name) = strip_brackets(type_name) { diff --git a/src/types/maybe_undefined.rs b/src/types/maybe_undefined.rs index 267f058a..a89634cb 100644 --- a/src/types/maybe_undefined.rs +++ b/src/types/maybe_undefined.rs @@ -47,19 +47,14 @@ use crate::{InputType, InputValueError, InputValueResult, Value, registry}; /// # }); /// ``` #[allow(missing_docs)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] +#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, Default)] pub enum MaybeUndefined { + #[default] Undefined, Null, Value(T), } -impl Default for MaybeUndefined { - fn default() -> Self { - Self::Undefined - } -} - impl MaybeUndefined { /// Returns true if the `MaybeUndefined` is undefined. #[inline] diff --git a/value/src/deserializer.rs b/value/src/deserializer.rs index d4fc6277..f3a02d96 100644 --- a/value/src/deserializer.rs +++ b/value/src/deserializer.rs @@ -47,7 +47,7 @@ impl From for DeserializerError { impl ConstValue { #[inline] - fn unexpected(&self) -> Unexpected { + fn unexpected(&self) -> Unexpected<'_> { match self { ConstValue::Null => Unexpected::Unit, ConstValue::Number(_) => Unexpected::Other("number"), diff --git a/value/src/lib.rs b/value/src/lib.rs index 73930bc2..f34b75e6 100644 --- a/value/src/lib.rs +++ b/value/src/lib.rs @@ -128,9 +128,10 @@ impl<'de> Deserialize<'de> for Name { /// be deserialized. /// /// [Reference](https://spec.graphql.org/June2018/#Value). -#[derive(Clone, Debug, Eq)] +#[derive(Clone, Debug, Eq, Default)] pub enum ConstValue { /// `null`. + #[default] Null, /// A number. Number(Number), @@ -330,12 +331,6 @@ impl ConstValue { } } -impl Default for ConstValue { - fn default() -> Self { - Self::Null - } -} - impl Display for ConstValue { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { @@ -374,11 +369,12 @@ impl TryFrom for serde_json::Value { /// `Upload` and `Variable` cannot be deserialized. /// /// [Reference](https://spec.graphql.org/June2018/#Value). -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, Default)] pub enum Value { /// A variable, without the `$`. Variable(Name), /// `null`. + #[default] Null, /// A number. Number(Number), @@ -461,12 +457,6 @@ impl Value { } } -impl Default for Value { - fn default() -> Self { - Self::Null - } -} - impl Display for Value { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { diff --git a/value/src/value_serde.rs b/value/src/value_serde.rs index a66f589d..4875a4da 100644 --- a/value/src/value_serde.rs +++ b/value/src/value_serde.rs @@ -28,12 +28,11 @@ impl Serialize for ConstValue { ConstValue::List(v) => v.serialize(serializer), ConstValue::Object(v) => { #[cfg(feature = "raw_value")] - if v.len() == 1 { - if let Some(ConstValue::String(v)) = v.get(RAW_VALUE_TOKEN) { - if let Ok(v) = serde_json::value::RawValue::from_string(v.clone()) { - return v.serialize(serializer); - } - } + if v.len() == 1 + && let Some(ConstValue::String(v)) = v.get(RAW_VALUE_TOKEN) + && let Ok(v) = serde_json::value::RawValue::from_string(v.clone()) + { + return v.serialize(serializer); } v.serialize(serializer) } From 1d0e6fe27d137e14c0574ea8bb35956b6360da5a Mon Sep 17 00:00:00 2001 From: Ivan Petkov Date: Sun, 9 Nov 2025 09:40:47 -0800 Subject: [PATCH 2/2] Also fix warnings in tests --- .github/workflows/ci.yml | 2 +- benches/static_schema.rs | 1 + tests/error_ext.rs | 2 ++ tests/introspection.rs | 1 + tests/lifetime.rs | 4 ++++ tests/oneof_object.rs | 1 + tests/proc_macro_in_macro_rules.rs | 4 ++++ tests/result.rs | 3 +++ tests/validators.rs | 1 + 9 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 206812a2..48f67fe2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,7 +96,7 @@ jobs: toolchain: ${{ matrix.rust }} components: clippy - name: Check with clippy - run: cargo clippy --all + run: cargo clippy --all --all-features --all-targets book_examples: name: Test book examples diff --git a/benches/static_schema.rs b/benches/static_schema.rs index 5e056b79..dd4de216 100644 --- a/benches/static_schema.rs +++ b/benches/static_schema.rs @@ -321,6 +321,7 @@ impl QueryRoot { } } +#[allow(clippy::duplicated_attributes)] #[derive(Interface)] #[graphql( field(name = "id", ty = "&str"), diff --git a/tests/error_ext.rs b/tests/error_ext.rs index 51d886c1..8105ea93 100644 --- a/tests/error_ext.rs +++ b/tests/error_ext.rs @@ -180,10 +180,12 @@ pub async fn test_failure2() { } } + #[allow(dead_code)] struct Query; #[Object] impl Query { + #[allow(dead_code)] async fn failure(&self) -> Result { Err(MyError::Error1) } diff --git a/tests/introspection.rs b/tests/introspection.rs index f514b8a3..b247f8b8 100644 --- a/tests/introspection.rs +++ b/tests/introspection.rs @@ -1228,6 +1228,7 @@ pub async fn test_introspection_subscription() { #[tokio::test] pub async fn test_disable_introspection() { #[derive(SimpleObject)] + #[expect(dead_code)] struct Query { value: i32, } diff --git a/tests/lifetime.rs b/tests/lifetime.rs index 23bb6f91..d701af29 100644 --- a/tests/lifetime.rs +++ b/tests/lifetime.rs @@ -4,10 +4,12 @@ use async_graphql::*; use static_assertions_next::_core::marker::PhantomData; #[derive(SimpleObject)] +#[allow(dead_code)] struct ObjA<'a> { value: &'a i32, } +#[expect(dead_code)] struct ObjB<'a>(PhantomData<&'a i32>); #[Object] @@ -19,12 +21,14 @@ impl<'a> ObjB<'a> { } #[derive(Union)] +#[expect(dead_code)] enum MyUnion1<'a> { ObjA(ObjA<'a>), } #[derive(Interface)] #[graphql(field(name = "value", ty = "&&'a i32"))] +#[expect(dead_code)] enum MyInterface<'a> { ObjA(ObjA<'a>), } diff --git a/tests/oneof_object.rs b/tests/oneof_object.rs index a0d504c3..ce73a072 100644 --- a/tests/oneof_object.rs +++ b/tests/oneof_object.rs @@ -271,6 +271,7 @@ async fn test_oneof_object_vec() { use async_graphql::*; #[derive(SimpleObject)] + #[expect(dead_code)] pub struct User { name: String, } diff --git a/tests/proc_macro_in_macro_rules.rs b/tests/proc_macro_in_macro_rules.rs index 0dbbe73f..6359dee0 100644 --- a/tests/proc_macro_in_macro_rules.rs +++ b/tests/proc_macro_in_macro_rules.rs @@ -9,6 +9,7 @@ pub async fn test_object() { #[async_graphql::Object] impl $test_name { + #[allow(dead_code)] async fn value(&self) -> i32 { self.value } @@ -30,6 +31,7 @@ pub async fn test_subscription() { #[async_graphql::Subscription] impl $test_name { + #[allow(dead_code)] async fn value(&self) -> impl futures_util::stream::Stream + 'static { let value = self.value; futures_util::stream::once(async move { value }) @@ -46,6 +48,7 @@ pub async fn test_scalar() { macro_rules! test_data { ($test_name:ident) => { #[derive(Debug, Clone)] + #[expect(dead_code)] pub struct $test_name(i64); #[async_graphql::Scalar] @@ -74,6 +77,7 @@ pub async fn test_oneof_object_type() { macro_rules! test_data { ($test_name:ident, $type1:ty, $type2:ty) => { #[derive(async_graphql::OneofObject)] + #[expect(dead_code)] enum $test_name { Type1($type1), Type2($type2), diff --git a/tests/result.rs b/tests/result.rs index 0d1100c4..64314d4a 100644 --- a/tests/result.rs +++ b/tests/result.rs @@ -113,6 +113,7 @@ pub async fn test_custom_error() { #[derive(Interface)] #[graphql(field(name = "value2", ty = "i32"))] + #[expect(dead_code)] enum MyInterface { MyObj(MyObj), } @@ -121,11 +122,13 @@ pub async fn test_custom_error() { #[Object] impl Query { + #[allow(dead_code)] async fn value(&self) -> Result { Err(MyError) } } + #[expect(dead_code)] struct Subscription; #[Subscription] diff --git a/tests/validators.rs b/tests/validators.rs index 21ea3557..3098c8cb 100644 --- a/tests/validators.rs +++ b/tests/validators.rs @@ -8,6 +8,7 @@ use futures_util::{Stream, StreamExt}; #[tokio::test] pub async fn test_all_validator() { + #[expect(dead_code)] struct Query; #[Object]