Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty #[derive(Accounts)] struct does not compile with cpi feature #2758

Closed
cavemanloverboy opened this issue Jan 3, 2024 · 1 comment
Closed
Labels
duplicate This issue or pull request already exists lang

Comments

@cavemanloverboy
Copy link
Contributor

cavemanloverboy commented Jan 3, 2024

The autogenerated cpi code always adds a lifetime parameter. For some

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

the macros generate

#[cfg(feature = "cpi")]
pub mod cpi {
    use super::*;
    use std::marker::PhantomData;
    pub struct Return<T> {
        phantom: std::marker::PhantomData<T>,
    }
    impl<T: AnchorDeserialize> Return<T> {
        pub fn get(&self) -> T {
            let (_key, data) = anchor_lang::solana_program::program::get_return_data()
                .unwrap();
            T::try_from_slice(&data).unwrap()
        }
    }
    pub fn initialize<'a, 'b, 'c, 'info>(
        ctx: anchor_lang::context::CpiContext<
            'a,
            'b,
            'c,
            'info,
            crate::cpi::accounts::Initialize<'info>,
        >,
        data: Vec<u8>,
    ) -> anchor_lang::Result<()> {
    // redacted

which does not compile due to the added lifetime parameter on crate::cpi::accounts::Initialize<'info>

@acheroncrypto acheroncrypto added duplicate This issue or pull request already exists lang labels Jan 3, 2024
@acheroncrypto
Copy link
Collaborator

Duplicate of #1628

There is also a draft PR to solve it: #1659

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists lang
Projects
None yet
Development

No branches or pull requests

2 participants