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

lang: repr override for zero copy #1273

Merged
merged 1 commit into from Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion lang/attribute/account/src/lib.rs
Expand Up @@ -291,9 +291,21 @@ pub fn zero_copy(
) -> proc_macro::TokenStream {
let account_strct = parse_macro_input!(item as syn::ItemStruct);

// Takes the first repr. It's assumed that more than one are not on the
// struct.
let attr = account_strct
.attrs
.iter()
.find(|attr| anchor_syn::parser::tts_to_string(&attr.path) == "repr");

let repr = match attr {
Some(_attr) => quote! {},
None => quote! {#[repr(C)]},
};

proc_macro::TokenStream::from(quote! {
#[derive(anchor_lang::__private::ZeroCopyAccessor, Copy, Clone)]
#[repr(C)]
#repr
#account_strct
})
}
Expand Down
1 change: 1 addition & 0 deletions tests/zero-copy/programs/zero-copy/src/lib.rs
Expand Up @@ -139,6 +139,7 @@ pub struct UpdateLargeAccount<'info> {

#[account(zero_copy)]
#[derive(Default)]
#[repr(packed)]
pub struct Foo {
pub authority: Pubkey,
pub data: u64,
Expand Down