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

fix: unused fields warn, fields for inner structs of derived BorshSch… #172

Merged
merged 1 commit into from
Jul 4, 2023

Conversation

dj8yfo
Copy link
Collaborator

@dj8yfo dj8yfo commented Jul 3, 2023

…ema method

Resolves #111
An example of repro

@@ -96,6 +96,7 @@ pub fn process_enum(input: &ItemEnum, cratename: Ident) -> syn::Result<TokenStre
}
}
anonymous_defs.extend(quote! {
#[allow(dead_code)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

@dj8yfo I don't have all the necessary context here, so I would ask you to look into it: do we even need those unused fields in the struct? I somehow feel uneasy about silencing the compiler here as it might indicate that something is missing / not implemented when it should be.

Copy link
Collaborator Author

@dj8yfo dj8yfo Jul 4, 2023

Choose a reason for hiding this comment

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

I've looked into it.
The fields with their types and possibly #[borsh_skip] attributes are needed to derive correct inner impl BorshSchema for inner structs inside of method of BorshSchema impl for enum. So that type info is still needed.
The compiler is complaining that these structs never get constructed and their fields read.
Which is kind of normal, provided that the structs are invisible outside of the method's scope.
They're accessed by their types instead : <InnerStruct>::declaration(), <InnerStruct as borsh::BorshSchema>::add_definitions_recursively(definitions).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for looking into it!

@dj8yfo dj8yfo force-pushed the cloned_enum_variant_unused branch from 77f3cd3 to f177635 Compare July 4, 2023 09:32
@dj8yfo dj8yfo marked this pull request as ready for review July 4, 2023 10:06
@frol frol merged commit 036d0c2 into near:master Jul 4, 2023
5 checks passed
@dj8yfo dj8yfo mentioned this pull request Aug 2, 2023
@frol frol mentioned this pull request Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cloned enum struct variant fields are reported as unused
2 participants