Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fully qualified path to types in generated code #1195

Merged
merged 1 commit into from
Oct 6, 2023

Conversation

tpoliaw
Copy link
Contributor

@tpoliaw tpoliaw commented Oct 2, 2023

If user code has a type alias (or custom type) called Result or Option etc,
this would be used instead of the intended standard library types causing
surprising compile errors from generated code.

Using the fully qualified path allows the generated code to be isolated
from user types.

Fixes #1194

@tpoliaw
Copy link
Contributor Author

tpoliaw commented Oct 2, 2023

Looking at this again there are many other cases that could fail in the same way (Some, None, Send, Sync etc). I will try and go through and add the paths for the other types but for traits/types that are available in both std and core, is there a preference for one over the other?

quote! {
.deprecated(::std::option::Option::#reason)
.deprecated(#reason)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worked before but I changed it to make it more clear that the types are correctly qualified. I spent quite a while trying to track down an expected identifier, found :: error caused by the doubly qualified path (::std::option::Option::std::option::Option::Some(...) after only changing the other line.

Happy to revert if preferred.

@LegNeato
Copy link
Member

LegNeato commented Oct 2, 2023

Looking at this again there are many other cases that could fail in the same way (Some, None, Send, Sync etc). I will try and go through and add the paths for the other types but for traits/types that are available in both std and core, is there a preference for one over the other?

The preference would be core over std where possible. Last I looked we still build on no_std.

@tpoliaw
Copy link
Contributor Author

tpoliaw commented Oct 3, 2023

Last I looked we still build on no_std

Does that include using the derived code? There are several instances of things like String and Box floating around that presumably require std.

I will update the changes in this PR to use core though. Should existing references to ::std::* in derives be updated at the same time?

If user code has a type alias (or custom type) called `Result` or
`Option` etc, this would be used instead of the intended standard
library types causing surprising compile errors from generated code.

Using the fully qualified path allows the generated code to be isolated
from user types.

Includes two basic regression tests covering `Result` and `Send`.

Fixes graphql-rust#1194
@tpoliaw tpoliaw changed the title Use fully qualified path to Result in generated code Use fully qualified path to types in generated code Oct 4, 2023
@LegNeato
Copy link
Member

LegNeato commented Oct 5, 2023

Sorry, I was mistaken...I got my wires crossed with wasm

@LegNeato LegNeato merged commit 801820a into graphql-rust:master Oct 6, 2023
177 checks passed
@LegNeato
Copy link
Member

LegNeato commented Oct 6, 2023

Awesome, thanks!

@tyranron tyranron added the enhancement Improvement of existing features or bugfix label Oct 13, 2023
@tyranron tyranron added this to the 0.16.0 milestone Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features or bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GraphQLInputObject macro fails if crate has a local type alias named "Result"
3 participants