From 17a02fa7667b262565c8d5c842e15c3fc9dad258 Mon Sep 17 00:00:00 2001 From: tyranron Date: Fri, 13 Oct 2023 19:28:42 +0300 Subject: [PATCH] Correct fully qualified paths in generated code (#1195, #1194) --- juniper/src/macros/reflect.rs | 12 +++++------ juniper_codegen/src/common/deprecation.rs | 10 ++++----- juniper_codegen/src/common/field/arg.rs | 4 +++- juniper_codegen/src/common/field/mod.rs | 12 ++++++++--- juniper_codegen/src/common/gen.rs | 14 +++++++++---- juniper_codegen/src/graphql_enum/mod.rs | 21 ++++++++++++++----- .../src/graphql_input_object/mod.rs | 9 ++++++-- juniper_codegen/src/graphql_interface/mod.rs | 19 +++++++++++------ juniper_codegen/src/graphql_object/mod.rs | 11 +++++++--- juniper_codegen/src/graphql_scalar/mod.rs | 16 +++++++++----- .../src/graphql_subscription/mod.rs | 5 ++++- juniper_codegen/src/graphql_union/attr.rs | 2 +- juniper_codegen/src/graphql_union/derive.rs | 7 +++++-- juniper_codegen/src/graphql_union/mod.rs | 17 ++++++++++----- juniper_codegen/src/scalar_value/mod.rs | 21 +++++++++---------- 15 files changed, 120 insertions(+), 60 deletions(-) diff --git a/juniper/src/macros/reflect.rs b/juniper/src/macros/reflect.rs index 563b28df..5e344d8b 100644 --- a/juniper/src/macros/reflect.rs +++ b/juniper/src/macros/reflect.rs @@ -516,7 +516,7 @@ macro_rules! assert_implemented_for { <$implementor as $crate::macros::reflect::BaseType<$scalar>>::NAME, "`: missing implementer reference in interface's `for` attribute.", ); - ::std::panic!("{}", MSG); + ::core::panic!("{}", MSG); } })* }; @@ -544,7 +544,7 @@ macro_rules! assert_interfaces_impls { <$implementers as $crate::macros::reflect::BaseType<$scalar>>::NAME, "`: missing interface reference in implementer's `impl` attribute.", ); - ::std::panic!("{}", MSG); + ::core::panic!("{}", MSG); } })* }; @@ -576,7 +576,7 @@ macro_rules! assert_transitive_impls { <$implementor as $crate::macros::reflect::BaseType<$scalar>>::NAME, "`." ); - ::std::panic!("{}", MSG); + ::core::panic!("{}", MSG); } })* }; @@ -674,7 +674,7 @@ macro_rules! assert_subtype { $crate::format_type!(BASE_RETURN_TY, BASE_RETURN_WRAPPED_VAL), "`.", ); - ::std::panic!("{}", MSG); + ::core::panic!("{}", MSG); } }; }; @@ -855,7 +855,7 @@ macro_rules! assert_field_args { }; const ERROR_MSG: &str = $crate::const_concat!(ERR_PREFIX, "Field `", FIELD_NAME, "`: ", MSG); - ::std::panic!("{}", ERROR_MSG); + ::core::panic!("{}", ERROR_MSG); } }; }; @@ -911,7 +911,7 @@ macro_rules! checked_hash { <$impl_ty as $crate::macros::reflect::BaseType<$scalar>>::NAME, "`." ); - ::std::panic!("{}", MSG) + ::core::panic!("{}", MSG) } }}; } diff --git a/juniper_codegen/src/common/deprecation.rs b/juniper_codegen/src/common/deprecation.rs index 51eed825..fb7af234 100644 --- a/juniper_codegen/src/common/deprecation.rs +++ b/juniper_codegen/src/common/deprecation.rs @@ -102,12 +102,12 @@ impl Directive { impl ToTokens for Directive { fn to_tokens(&self, into: &mut TokenStream) { - let reason = self.reason.as_ref().map_or_else( - || quote! { ::core::option::Option::None }, - |text| quote! { ::core::option::Option::Some(#text) }, - ); + let reason = self + .reason + .as_ref() + .map_or_else(|| quote! { None }, |text| quote! { Some(#text) }); quote! { - .deprecated(#reason) + .deprecated(::core::option::Option::#reason) } .to_tokens(into); } diff --git a/juniper_codegen/src/common/field/arg.rs b/juniper_codegen/src/common/field/arg.rs index b425eb19..20c1b1f6 100644 --- a/juniper_codegen/src/common/field/arg.rs +++ b/juniper_codegen/src/common/field/arg.rs @@ -341,7 +341,9 @@ impl OnMethod { quote! { match #arg { ::core::result::Result::Ok(v) => v, - ::core::result::Result::Err(e) => return ::std::boxed::Box::pin(async { ::core::result::Result::Err(e) }), + ::core::result::Result::Err(e) => return ::std::boxed::Box::pin(async { + ::core::result::Result::Err(e) + }), } } } else { diff --git a/juniper_codegen/src/common/field/mod.rs b/juniper_codegen/src/common/field/mod.rs index dedcd1bc..092967f7 100644 --- a/juniper_codegen/src/common/field/mod.rs +++ b/juniper_codegen/src/common/field/mod.rs @@ -354,14 +354,20 @@ impl Definition { async move { let ex = executor.as_executor(); match res2 { - ::core::result::Result::Ok(::core::option::Option::Some((ctx, r))) => { + ::core::result::Result::Ok( + ::core::option::Option::Some((ctx, r)), + ) => { let sub = ex.replaced_context(ctx); sub.resolve_with_ctx_async(&(), &r) .await .map_err(|e| ex.new_error(e)) } - ::core::result::Result::Ok(::core::option::Option::None) => ::core::result::Result::Ok(::juniper::Value::null()), - ::core::result::Result::Err(e) => ::core::result::Result::Err(ex.new_error(e)), + ::core::result::Result::Ok(::core::option::Option::None) => { + ::core::result::Result::Ok(::juniper::Value::null()) + } + ::core::result::Result::Err(e) => { + ::core::result::Result::Err(ex.new_error(e)) + } } } }); diff --git a/juniper_codegen/src/common/gen.rs b/juniper_codegen/src/common/gen.rs index d4080772..22d350d6 100644 --- a/juniper_codegen/src/common/gen.rs +++ b/juniper_codegen/src/common/gen.rs @@ -13,8 +13,12 @@ pub(crate) fn sync_resolving_code() -> TokenStream { quote! { ::juniper::IntoResolvable::into_resolvable(res, executor.context()) .and_then(|res| match res { - ::core::option::Option::Some((ctx, r)) => executor.replaced_context(ctx).resolve_with_ctx(info, &r), - ::core::option::Option::None => ::core::result::Result::Ok(::juniper::Value::null()), + ::core::option::Option::Some((ctx, r)) => { + executor.replaced_context(ctx).resolve_with_ctx(info, &r) + } + ::core::option::Option::None => { + ::core::result::Result::Ok(::juniper::Value::null()) + } }) } } @@ -39,8 +43,10 @@ pub(crate) fn async_resolving_code(ty: Option<&syn::Type>) -> TokenStream { ::core::option::Option::Some((ctx, r)) => { let subexec = executor.replaced_context(ctx); subexec.resolve_with_ctx_async(info, &r).await - }, - ::core::option::Option::None => ::core::result::Result::Ok(::juniper::Value::null()), + } + ::core::option::Option::None => { + ::core::result::Result::Ok(::juniper::Value::null()) + } } })) } diff --git a/juniper_codegen/src/graphql_enum/mod.rs b/juniper_codegen/src/graphql_enum/mod.rs index d6f30c10..048f6373 100644 --- a/juniper_codegen/src/graphql_enum/mod.rs +++ b/juniper_codegen/src/graphql_enum/mod.rs @@ -450,7 +450,9 @@ impl Definition { for #ident #ty_generics #where_clause { - fn name(_ : &Self::TypeInfo) -> ::core::option::Option<&'static ::core::primitive::str> { + fn name( + _ : &Self::TypeInfo, + ) -> ::core::option::Option<&'static ::core::primitive::str> { ::core::option::Option::Some(#name) } @@ -489,7 +491,9 @@ impl Definition { let name = &v.name; quote! { - Self::#ident => ::core::result::Result::Ok(::juniper::Value::scalar(::std::string::String::from(#name))), + Self::#ident => ::core::result::Result::Ok(::juniper::Value::scalar( + ::std::string::String::from(#name), + )), } }); @@ -509,7 +513,10 @@ impl Definition { type Context = #context; type TypeInfo = (); - fn type_name<'__i>(&self, info: &'__i Self::TypeInfo) -> ::core::option::Option<&'__i ::core::primitive::str> { + fn type_name<'__i>( + &self, + info: &'__i Self::TypeInfo, + ) -> ::core::option::Option<&'__i ::core::primitive::str> { >::name(info) } @@ -588,10 +595,14 @@ impl Definition { { type Error = ::std::string::String; - fn from_input_value(v: &::juniper::InputValue<#scalar>) -> ::core::result::Result { + fn from_input_value( + v: &::juniper::InputValue<#scalar>, + ) -> ::core::result::Result { match v.as_enum_value().or_else(|| v.as_string_value()) { #( #variants )* - _ => ::core::result::Result::Err(::std::format!("Unknown enum value: {}", v)), + _ => ::core::result::Result::Err( + ::std::format!("Unknown enum value: {}", v), + ), } } } diff --git a/juniper_codegen/src/graphql_input_object/mod.rs b/juniper_codegen/src/graphql_input_object/mod.rs index 9d3c3ad2..baa091a0 100644 --- a/juniper_codegen/src/graphql_input_object/mod.rs +++ b/juniper_codegen/src/graphql_input_object/mod.rs @@ -479,7 +479,9 @@ impl Definition { for #ident #ty_generics #where_clause { - fn name(_: &Self::TypeInfo) -> ::core::option::Option<&'static ::core::primitive::str> { + fn name( + _: &Self::TypeInfo, + ) -> ::core::option::Option<&'static ::core::primitive::str> { ::core::option::Option::Some(#name) } @@ -524,7 +526,10 @@ impl Definition { type Context = #context; type TypeInfo = (); - fn type_name<'__i>(&self, info: &'__i Self::TypeInfo) -> ::core::option::Option<&'__i ::core::primitive::str> { + fn type_name<'__i>( + &self, + info: &'__i Self::TypeInfo, + ) -> ::core::option::Option<&'__i ::core::primitive::str> { >::name(info) } } diff --git a/juniper_codegen/src/graphql_interface/mod.rs b/juniper_codegen/src/graphql_interface/mod.rs index 9a1ec21c..a5274dc0 100644 --- a/juniper_codegen/src/graphql_interface/mod.rs +++ b/juniper_codegen/src/graphql_interface/mod.rs @@ -460,7 +460,9 @@ impl Definition { syn::GenericParam::Const(_) => return None, }; Some(quote! { - ::core::marker::PhantomData<::std::sync::atomic::AtomicPtr>> + ::core::marker::PhantomData< + ::core::sync::atomic::AtomicPtr> + > }) }); quote! { __Phantom(#(#phantom_params),*) } @@ -474,7 +476,7 @@ impl Definition { .map(|(ty, ident)| { quote! { #[automatically_derived] - impl #interface_impl_gens ::std::convert::From<#ty> + impl #interface_impl_gens ::core::convert::From<#ty> for #alias_ident #interface_ty_gens #interface_where_clause { @@ -487,7 +489,7 @@ impl Definition { quote! { #[automatically_derived] - #[derive(::std::clone::Clone, ::core::marker::Copy, ::std::fmt::Debug)] + #[derive(::core::clone::Clone, ::core::marker::Copy, ::core::fmt::Debug)] #[doc = #enum_doc] #vis enum #enum_ident #enum_gens { #( #[doc(hidden)] #variants_idents(#variant_gens_pars), )* @@ -715,8 +717,10 @@ impl Definition { for #ty #ty_generics #where_clause { - fn name(_ : &Self::TypeInfo) -> ::core::option::Option<&'static ::core::primitive::str> { - ::std::option::Option::Some(#name) + fn name( + _ : &Self::TypeInfo, + ) -> ::core::option::Option<&'static ::core::primitive::str> { + ::core::option::Option::Some(#name) } fn meta<'r>( @@ -784,7 +788,10 @@ impl Definition { type Context = #context; type TypeInfo = (); - fn type_name<'__i>(&self, info: &'__i Self::TypeInfo) -> std::option::Option<&'__i ::core::primitive::str> { + fn type_name<'__i>( + &self, + info: &'__i Self::TypeInfo, + ) -> ::core::option::Option<&'__i ::core::primitive::str> { >::name(info) } diff --git a/juniper_codegen/src/graphql_object/mod.rs b/juniper_codegen/src/graphql_object/mod.rs index 8d772561..57613077 100644 --- a/juniper_codegen/src/graphql_object/mod.rs +++ b/juniper_codegen/src/graphql_object/mod.rs @@ -457,7 +457,9 @@ impl Definition { #[automatically_derived] impl #impl_generics ::juniper::GraphQLType<#scalar> for #ty #where_clause { - fn name(_ : &Self::TypeInfo) -> ::core::option::Option<&'static ::core::primitive::str> { + fn name( + _ : &Self::TypeInfo, + ) -> ::core::option::Option<&'static ::core::primitive::str> { ::core::option::Option::Some(#name) } @@ -626,7 +628,7 @@ impl Definition { let resolve = if field.is_async { quote! { - ::std::panic!( + ::core::panic!( "Tried to resolve async field `{}` on type `{}` with a sync resolver", #name, >::NAME, @@ -783,7 +785,10 @@ impl Definition { type Context = #context; type TypeInfo = (); - fn type_name<'__i>(&self, info: &'__i Self::TypeInfo) -> ::core::option::Option<&'__i ::core::primitive::str> { + fn type_name<'__i>( + &self, + info: &'__i Self::TypeInfo, + ) -> ::core::option::Option<&'__i ::core::primitive::str> { >::name(info) } diff --git a/juniper_codegen/src/graphql_scalar/mod.rs b/juniper_codegen/src/graphql_scalar/mod.rs index ae4d5377..d6af3016 100644 --- a/juniper_codegen/src/graphql_scalar/mod.rs +++ b/juniper_codegen/src/graphql_scalar/mod.rs @@ -375,7 +375,9 @@ impl Definition { impl #impl_gens ::juniper::GraphQLType<#scalar> for #ty #where_clause { - fn name(_: &Self::TypeInfo) -> ::core::option::Option<&'static ::core::primitive::str> { + fn name( + _: &Self::TypeInfo, + ) -> ::core::option::Option<&'static ::core::primitive::str> { ::core::option::Option::Some(#name) } @@ -416,7 +418,10 @@ impl Definition { type Context = (); type TypeInfo = (); - fn type_name<'i>(&self, info: &'i Self::TypeInfo) -> ::core::option::Option<&'i ::core::primitive::str> { + fn type_name<'i>( + &self, + info: &'i Self::TypeInfo, + ) -> ::core::option::Option<&'i ::core::primitive::str> { >::name(info) } @@ -454,9 +459,8 @@ impl Definition { selection_set: ::core::option::Option<&'b [::juniper::Selection<'_, #scalar>]>, executor: &'b ::juniper::Executor<'_, '_, Self::Context, #scalar>, ) -> ::juniper::BoxFuture<'b, ::juniper::ExecutionResult<#scalar>> { - use ::juniper::futures::future; let v = ::juniper::GraphQLValue::resolve(self, info, selection_set, executor); - ::std::boxed::Box::pin(future::ready(v)) + ::std::boxed::Box::pin(::juniper::futures::future::ready(v)) } } } @@ -507,7 +511,9 @@ impl Definition { { type Error = ::juniper::executor::FieldError<#scalar>; - fn from_input_value(input: &::juniper::InputValue<#scalar>) -> ::core::result::Result { + fn from_input_value( + input: &::juniper::InputValue<#scalar>, + ) -> ::core::result::Result { #from_input_value .map_err(::juniper::executor::IntoFieldError::<#scalar>::into_field_error) } diff --git a/juniper_codegen/src/graphql_subscription/mod.rs b/juniper_codegen/src/graphql_subscription/mod.rs index 37b99d86..47af4b30 100644 --- a/juniper_codegen/src/graphql_subscription/mod.rs +++ b/juniper_codegen/src/graphql_subscription/mod.rs @@ -49,7 +49,10 @@ impl Definition { type Context = #context; type TypeInfo = (); - fn type_name<'__i>(&self, info: &'__i Self::TypeInfo) -> ::core::option::Option<&'__i ::core::primitive::str> { + fn type_name<'__i>( + &self, + info: &'__i Self::TypeInfo, + ) -> ::core::option::Option<&'__i ::core::primitive::str> { >::name(info) } diff --git a/juniper_codegen/src/graphql_union/attr.rs b/juniper_codegen/src/graphql_union/attr.rs index 006ad226..bd7067e3 100644 --- a/juniper_codegen/src/graphql_union/attr.rs +++ b/juniper_codegen/src/graphql_union/attr.rs @@ -203,7 +203,7 @@ fn parse_variant_from_trait_method( // no other options here, until the `juniper::GraphQLType` itself will allow // to do it in some cleverer way. let resolver_check = parse_quote! { - ({ #resolver_code } as ::std::option::Option<&#ty>).is_some() + ({ #resolver_code } as ::core::option::Option<&#ty>).is_some() }; Some(VariantDefinition { diff --git a/juniper_codegen/src/graphql_union/derive.rs b/juniper_codegen/src/graphql_union/derive.rs index c4bbaf6d..44f045e3 100644 --- a/juniper_codegen/src/graphql_union/derive.rs +++ b/juniper_codegen/src/graphql_union/derive.rs @@ -151,12 +151,15 @@ fn parse_variant_from_enum_variant( } } else { parse_quote! { - match self { #enum_ident::#var_ident(ref v) => ::core::option::Option::Some(v), _ => ::core::option::Option::None, } + match self { + #enum_ident::#var_ident(ref v) => ::core::option::Option::Some(v), + _ => ::core::option::Option::None, + } } }; let resolver_check = parse_quote! { - matches!(self, #enum_path(_)) + ::core::matches!(self, #enum_path(_)) }; Some(VariantDefinition { diff --git a/juniper_codegen/src/graphql_union/mod.rs b/juniper_codegen/src/graphql_union/mod.rs index 4ff361c8..7eb918db 100644 --- a/juniper_codegen/src/graphql_union/mod.rs +++ b/juniper_codegen/src/graphql_union/mod.rs @@ -473,7 +473,9 @@ impl Definition { #[automatically_derived] impl #impl_generics ::juniper::GraphQLType<#scalar> for #ty_full #where_clause { - fn name(_ : &Self::TypeInfo) -> ::core::option::Option<&'static ::core::primitive::str> { + fn name( + _ : &Self::TypeInfo, + ) -> ::core::option::Option<&'static ::core::primitive::str> { ::core::option::Option::Some(#name) } @@ -525,7 +527,10 @@ impl Definition { type Context = #context; type TypeInfo = (); - fn type_name<'__i>(&self, info: &'__i Self::TypeInfo) -> Option<&'__i ::core::primitive::str> { + fn type_name<'__i>( + &self, + info: &'__i Self::TypeInfo, + ) -> ::core::option::Option<&'__i ::core::primitive::str> { >::name(info) } @@ -535,7 +540,7 @@ impl Definition { info: &Self::TypeInfo, ) -> ::std::string::String { #( #match_variant_names )* - ::std::panic!( + ::core::panic!( "GraphQL union `{}` cannot be resolved into any of its \ variants in its current state", #name, @@ -742,7 +747,9 @@ impl VariantDefinition { return #resolving_code; } } - ::core::option::Option::None => return ::juniper::macros::helper::err_unnamed_type_fut(#ty_name), + ::core::option::Option::None => { + return ::juniper::macros::helper::err_unnamed_type_fut(#ty_name); + } } } } @@ -773,7 +780,7 @@ fn emerge_union_variants_from_attr( // we have no other options here, until the `juniper::GraphQLType` // itself will allow to do it in some cleverer way. let resolver_check = parse_quote! { - ({ #resolver_code } as ::std::option::Option<&#ty>).is_some() + ({ #resolver_code } as ::core::option::Option<&#ty>).is_some() }; if let Some(var) = variants.iter_mut().find(|v| v.ty == ty) { diff --git a/juniper_codegen/src/scalar_value/mod.rs b/juniper_codegen/src/scalar_value/mod.rs index 97294df9..1ec0b179 100644 --- a/juniper_codegen/src/scalar_value/mod.rs +++ b/juniper_codegen/src/scalar_value/mod.rs @@ -261,7 +261,7 @@ impl Definition { ( Method::AsStr, quote! { fn as_str(&self) -> ::core::option::Option<&::core::primitive::str> }, - quote! { ::std::convert::AsRef::as_ref(v) }, + quote! { ::core::convert::AsRef::as_ref(v) }, ), ( Method::AsString, @@ -332,7 +332,7 @@ impl Definition { quote! { #[automatically_derived] - impl #impl_gen ::std::convert::From<#var_ty> for #ty_ident #ty_gen + impl #impl_gen ::core::convert::From<#var_ty> for #ty_ident #ty_gen #where_clause { fn from(v: #var_ty) -> Self { @@ -341,8 +341,8 @@ impl Definition { } #[automatically_derived] - impl #impl_gen ::std::convert::From<#ty_ident #ty_gen> for ::core::option::Option<#var_ty> - #where_clause + impl #impl_gen ::core::convert::From<#ty_ident #ty_gen> + for ::core::option::Option<#var_ty> #where_clause { fn from(ty: #ty_ident #ty_gen) -> Self { if let #ty_ident::#var_ident #var_field = ty { @@ -354,9 +354,8 @@ impl Definition { } #[automatically_derived] - impl #lf_impl_gen ::std::convert::From<&'___a #ty_ident #ty_gen> for - ::core::option::Option<&'___a #var_ty> - #where_clause + impl #lf_impl_gen ::core::convert::From<&'___a #ty_ident #ty_gen> + for ::core::option::Option<&'___a #var_ty> #where_clause { fn from(ty: &'___a #ty_ident #ty_gen) -> Self { if let #ty_ident::#var_ident #var_field = ty { @@ -390,7 +389,7 @@ impl Definition { .as_mut() .unwrap() .predicates - .push(parse_quote! { #var_ty: ::std::fmt::Display }); + .push(parse_quote! { #var_ty: ::core::fmt::Display }); } } let (impl_gen, ty_gen, where_clause) = generics.split_for_impl(); @@ -403,15 +402,15 @@ impl Definition { .as_ref() .map_or_else(|| quote! { (v) }, |i| quote! { { #i: v } }); - quote! { Self::#var_ident #var_field => ::std::fmt::Display::fmt(v, f), } + quote! { Self::#var_ident #var_field => ::core::fmt::Display::fmt(v, f), } }); quote! { #[automatically_derived] - impl #impl_gen ::std::fmt::Display for #ident #ty_gen + impl #impl_gen ::core::fmt::Display for #ident #ty_gen #where_clause { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { match self { #( #arms )* }