Skip to content

lang: Fix instructions with no accounts causing compilation errors when using declare_program!#3567

Merged
acheroncrypto merged 3 commits into
otter-sec:masterfrom
acheroncrypto:lang-fix-instructions-with-no-accounts-causing-compilation-errors-when-using-declare_program
Feb 20, 2025
Merged

lang: Fix instructions with no accounts causing compilation errors when using declare_program!#3567
acheroncrypto merged 3 commits into
otter-sec:masterfrom
acheroncrypto:lang-fix-instructions-with-no-accounts-causing-compilation-errors-when-using-declare_program

Conversation

@acheroncrypto

Copy link
Copy Markdown
Collaborator

Problem

Instructions with no accounts result in compilation errors when they're used with declare_program!.

For example, using an IDL that has an instruction like the one mentioned in #3514 (comment)

{
  "name": "refresh_reserves_batch",
  "discriminator": [144, 110, 26, 103, 162, 204, 252, 147],
  "accounts": [],
  "args": [
    {
      "name": "skip_price_updates",
      "type": "bool"
    }
  ]
}

results in:

error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied
 --> programs/name/src/lib.rs:5:1
  |
5 | declare_program!(kamino);
  | ^^^^^^^^^^^^^^^^^^^^^^^^- help: remove these generics
  | |
  | expected 0 lifetime arguments
  |

A similar issue (#1628) with the cpi feature has existed roughly since the creation of Anchor, but this one is specifically for the cpi module generated using declare_program!. The benefit of using the IDL + macro approach here is that we have access to all instruction information (unlike with the cpi feature, where we only have access to the token stream), which we can then use to decide whether to add the generic lifetime or not.

Summary of changes

Fix instructions with no accounts causing compilation errors when using declare_program! by conditionally adding the lifetime parameter only when the instruction accounts are not empty.

Fixes #3514

@vercel

vercel Bot commented Feb 20, 2025

Copy link
Copy Markdown

@acheroncrypto is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@acheroncrypto acheroncrypto merged commit b26f7eb into otter-sec:master Feb 20, 2025
Otter-0x4ka5h pushed a commit to Otter-0x4ka5h/anchor that referenced this pull request Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

struct takes 0 lifetime arguments but 1 lifetime argument was supplied expected 0 lifetime arguments when using declare_program

1 participant