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

[Draft] Don't include PhantomData fields in IdlBuild impl #3433

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions lang/syn/src/idl/defined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub fn gen_idl_type_def_struct(
.map(|f| gen_idl_field(f, generic_params, no_docs))
.collect::<Result<Vec<_>>>()?
.into_iter()
.filter(|(t,_)| !t.is_empty())
.unzip::<_, _, Vec<_>, Vec<_>>();

(
Expand All @@ -100,6 +101,7 @@ pub fn gen_idl_type_def_struct(
.map(|f| gen_idl_type(&f.ty, generic_params))
.collect::<Result<Vec<_>>>()?
.into_iter()
.filter(|(t,_)| !t.is_empty())
.unzip::<_, Vec<_>, Vec<_>, Vec<_>>();

(
Expand Down Expand Up @@ -337,6 +339,10 @@ fn gen_idl_field(
};
let (ty, defined) = gen_idl_type(&field.ty, generic_params)?;

if ty.is_empty() {
return Ok((ty, defined));
}

Ok((
quote! {
#idl::IdlField {
Expand Down Expand Up @@ -424,6 +430,9 @@ pub fn gen_idl_type(
syn::Type::Path(path) if the_only_segment_is(path, "Pubkey") => {
Ok((quote! { #idl::IdlType::Pubkey }, vec![]))
}
syn::Type::Path(path) if the_only_segment_is(path, "PhantomData") => {
Ok((TokenStream::new(), vec![]))
}
Comment on lines +433 to +435
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: match arms more or less follow the order of IdlType, so it would be great if you could move this logic either inside the Defined impl:

// Defined
syn::Type::Path(path) => {

or just above it.

syn::Type::Path(path) if the_only_segment_is(path, "Option") => {
let segment = get_first_segment(path);
let arg = get_angle_bracketed_type_args(segment)
Expand Down