Skip to content

Commit

Permalink
lang: Allow custom lifetime for Accounts structure (#2741)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aursen authored Dec 21, 2023
1 parent 51ae380 commit f6a1525
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lang/syn/src/codegen/accounts/to_account_infos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn generate(accs: &AccountsStruct) -> proc_macro2::TokenStream {
quote! {
#[automatically_derived]
impl<#combined_generics> anchor_lang::ToAccountInfos<#trait_generics> for #name <#struct_generics> #where_clause{
fn to_account_infos(&self) -> Vec<anchor_lang::solana_program::account_info::AccountInfo<'info>> {
fn to_account_infos(&self) -> Vec<anchor_lang::solana_program::account_info::AccountInfo<#trait_generics>> {
let mut account_infos = vec![];

#(#to_acc_infos)*
Expand Down
2 changes: 1 addition & 1 deletion lang/syn/src/codegen/accounts/try_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn generate(accs: &AccountsStruct) -> proc_macro2::TokenStream {
#[inline(never)]
fn try_accounts(
__program_id: &anchor_lang::solana_program::pubkey::Pubkey,
__accounts: &mut &'info [anchor_lang::solana_program::account_info::AccountInfo<'info>],
__accounts: &mut &#trait_generics [anchor_lang::solana_program::account_info::AccountInfo<#trait_generics>],
__ix_data: &[u8],
__bumps: &mut #bumps_struct_name,
__reallocs: &mut std::collections::BTreeSet<anchor_lang::solana_program::pubkey::Pubkey>,
Expand Down
5 changes: 5 additions & 0 deletions lang/tests/generics_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ use solana_program::pubkey::Pubkey;
// Needed to declare accounts.
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

#[derive(Accounts)]
pub struct CustomLifetime<'a> {
pub non_generic: UncheckedAccount<'a>,
}

#[derive(Accounts)]
pub struct GenericsTest<'info, T, U, const N: usize>
where
Expand Down

1 comment on commit f6a1525

@vercel
Copy link

@vercel vercel bot commented on f6a1525 Dec 21, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

anchor-docs – ./

anchor-lang.com
anchor-docs-git-master-200ms.vercel.app
anchor-docs-200ms.vercel.app
www.anchor-lang.com

Please sign in to comment.