Skip to content

Context lifetime 'c #3653

Description

@hrls

Simple code snippet of workaround for remaining accounts:

#[program]
pub mod t_rem_accs_new {
    use super::*;

    pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
        #[derive(Accounts)]
        struct Foobar<'info> {
            #[account(mut)]
            foo: AccountInfo<'info>,

            #[account(mut)]
            bar: AccountInfo<'info>,
        }

        ctx.remaining_accounts
            .chunks_exact(2)
            .try_for_each(|mut accounts| -> Result<_> {
                Foobar::try_accounts(
                    &ID,
                    &mut accounts,
                    &[],
                    &mut Default::default(),
                    &mut Default::default(),
                )?;

                Ok(())
            })?;

        Ok(())
    }
}

#[derive(Accounts)]
pub struct Initialize {}

I have the following error using anchor 0.31.0, when anchor 0.28.0 build is okay. It's just me or something changed?

  --> programs/t_rem_accs_new/src/lib.rs:19:9
   |
9  |       pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
   |                         ---
   |                         |
   |                         has type `anchor_lang::context::Context<'_, '_, '1, '_, Initialize>`
   |                         has type `anchor_lang::context::Context<'_, '_, '_, '2, Initialize>`
...
19 | /         ctx.remaining_accounts
20 | |             .chunks_exact(2)
   | |____________________________^ argument requires that `'1` must outlive `'2`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions