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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions borsh-schema-derive-internal/src/enum_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!

#[derive(#cratename::BorshSchema)]
#anonymous_struct
});
Expand Down Expand Up @@ -158,8 +159,10 @@ mod tests {
borsh::schema::Definition
>
) {
#[allow(dead_code)]
#[derive(borsh :: BorshSchema)]
struct ABacon;
#[allow(dead_code)]
#[derive(borsh :: BorshSchema)]
struct AEggs;
<ABacon as borsh::BorshSchema>::add_definitions_recursively(definitions);
Expand Down Expand Up @@ -196,6 +199,7 @@ mod tests {
borsh::schema::Definition
>
) {
#[allow(dead_code)]
#[derive(borsh :: BorshSchema)]
struct ABacon;
<ABacon as borsh::BorshSchema>::add_definitions_recursively(definitions);
Expand Down Expand Up @@ -231,12 +235,16 @@ mod tests {
borsh::schema::Definition
>
) {
#[allow(dead_code)]
#[derive(borsh :: BorshSchema)]
struct ABacon;
#[allow(dead_code)]
#[derive(borsh :: BorshSchema)]
struct AEggs;
#[allow(dead_code)]
#[derive(borsh :: BorshSchema)]
struct ASalad(Tomatoes, Cucumber, Oil);
#[allow(dead_code)]
#[derive(borsh :: BorshSchema)]
struct ASausage {
wrapper: Wrapper,
Expand Down Expand Up @@ -288,17 +296,21 @@ mod tests {
borsh::schema::Definition
>
) {
#[allow(dead_code)]
#[derive(borsh :: BorshSchema)]
struct ABacon<C, W>(#[borsh_skip] ::core::marker::PhantomData<(C, W, )>);
#[allow(dead_code)]
#[derive(borsh :: BorshSchema)]
struct AEggs<C, W>(#[borsh_skip] ::core::marker::PhantomData<(C, W, )>);
#[allow(dead_code)]
#[derive(borsh :: BorshSchema)]
struct ASalad<C, W>(
Tomatoes,
C,
Oil,
#[borsh_skip] ::core::marker::PhantomData<(C, W, )>
);
#[allow(dead_code)]
#[derive(borsh :: BorshSchema)]
struct ASausage<C, W> {
wrapper: W,
Expand Down Expand Up @@ -361,6 +373,7 @@ mod tests {
borsh::schema::Definition
>
) {
#[allow(dead_code)]
#[derive(borsh :: BorshSchema)]
struct SideLeft<A, B>
(
Expand All @@ -371,6 +384,7 @@ mod tests {
A: Display + Debug,
B: Display + Debug,
;
#[allow(dead_code)]
#[derive(borsh :: BorshSchema)]
struct SideRight<A, B>
(
Expand Down
Loading