Skip to content

lang: Fix using data as an instruction parameter name in declare_program!#3574

Merged
acheroncrypto merged 3 commits intosolana-foundation:masterfrom
acheroncrypto:lang-fix-using-data-as-an-instruction-parameter-name-in-declare_program
Feb 26, 2025
Merged

lang: Fix using data as an instruction parameter name in declare_program!#3574
acheroncrypto merged 3 commits intosolana-foundation:masterfrom
acheroncrypto:lang-fix-using-data-as-an-instruction-parameter-name-in-declare_program

Conversation

@acheroncrypto
Copy link
Copy Markdown
Collaborator

Problem

Having an instruction parameter named data results in a compilation error when used with declare_program!

error[E0382]: borrow of moved value: `data`
 --> programs/declare-program/src/lib.rs:5:1
  |
5 | declare_program!(external);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^
  | |
  | value borrowed here after move
  | move occurs because `data` has type `Vec<u8>`, which does not implement the `Copy` trait
  |
  = note: this error originates in the macro `declare_program` (in Nightly builds, run with -Z macro-backtrace for more info)

This happens because that identifier is being used internally here:

https://github.com/coral-xyz/anchor/blob/b6b4f11a5c4b36e73dd13f9da1289af5ab242e95/lang/attribute/program/src/declare_program/mods/cpi.rs#L74

Summary of changes

  • Fix being unable to use data as an instruction parameter name in declare_program!
  • Add a compilation test

Fixes #3572

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 26, 2025

@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 added lang fix Bug fix PR labels Feb 26, 2025
@acheroncrypto acheroncrypto merged commit dac533e into solana-foundation:master Feb 26, 2025
0 of 9 checks passed
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

fix Bug fix PR lang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

declare_program macro returns error: value borrowed here after move

1 participant