I have problem of borrowing accounts mutably from remaining accounts. Not exactly how to use AccountInfo, as error says that accounts does not live long enough.I am using Anchor 0.29, Solana-Program 0.17.4.Previously it was working, after upgrade AccountInfo started falling with lifetime issue.Tried a bunch of stuff even tried to use std::mem::replace accounts, but nothing helped so far.This is the function I am trying to fix, I know it does not do anything meaningful yet, but I am trying to fix lifetime issue here:
fn swap_spl<'info>( authority: &AccountInfo<'info>, remaining_accounts: &mut Iter<AccountInfo<'info>>, scratch: &mut Scratch,) -> Result<AccountInfo<'info>> { let accounts: Vec<AccountInfo<'info>> = remaining_accounts.take(7).cloned().collect::<Vec<_>>(); SplSwapInfo::try_accounts( // Will be validated by the spl swap registry&Pubkey::default(),&mut &accounts[..],&[],&mut SplSwapInfoBumps::default(),&mut scratch.reallocs, )?; Ok(authority.to_account_info())}#[derive(Accounts)]pub struct SplSwapInfo<'info> { /// CHECK: pub swap_pool: AccountInfo<'info>, /// CHECK: pub authority: AccountInfo<'info>, /// CHECK: #[account(mut)] pub vault_a: AccountInfo<'info>, /// CHECK: #[account(mut)] pub vault_b: AccountInfo<'info>, /// CHECK: #[account(mut)] pub token_mint: AccountInfo<'info>, /// CHECK: #[account(mut)] pub fee_account: AccountInfo<'info>, /// The address of the swap program /// CHECK: pub swap_program: AccountInfo<'info>,}
- I tried using 'a:'info with &'a AccountInfo<'info> and even wise versa, does not help.
- Tried std::mem::replace accounts, does not help.
- Tried removing 'info lifetime at all, does not help.
The error itself is:
error[E0597]: `accounts` does not live long enough | | fn swap_spl<'info>( | ----- lifetime `'info` defined here... | let accounts: Vec<AccountInfo<'info>> = remaining_accounts.take(7).cloned().collect::<Vec<_>>(); | -------- ----------------------- type annotation requires that `accounts` is borrowed for `'info` | | | binding `accounts` declared here... | &mut &accounts[..], | ^^^^^^^^ borrowed value does not live long enough... | } | - `accounts` dropped here while still borrowed