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

Account::try_from lifetime is not useable #3341

Open
juchiast opened this issue Nov 1, 2024 · 2 comments
Open

Account::try_from lifetime is not useable #3341

juchiast opened this issue Nov 1, 2024 · 2 comments
Labels
bug Something isn't working lang

Comments

@juchiast
Copy link

juchiast commented Nov 1, 2024

Since 0.29, Account::try_from signature changed from

fn try_from(info: &AccountInfo<'a>) -> Result<Account<'a, T>> {

to

fn try_from(info: &'a AccountInfo<'a>) -> Result<Account<'a, T>> {

If I have an owned AccountInfo<'a> variable, I cannot borrow it again with lifetime 'a because the current scope is always smaller, for example:

fn foo<'a>(info: AccountInfo<'a>) {
    Account::try_from(&info); // not possible because reference cannot live as long as 'a
}
@juchiast
Copy link
Author

juchiast commented Nov 2, 2024

My use-case will be resolved with #3342

Generally, this is still an issue because it is very hard to create a &'a AccountInfo<'a>. AccountInfo<'a> invariant and cannot be cast to a shorter lifetime AccountInfo<'b>.

@acheroncrypto acheroncrypto added bug Something isn't working lang labels Nov 2, 2024
@acheroncrypto
Copy link
Collaborator

If I have an owned AccountInfo<'a> variable, I cannot borrow it again with lifetime 'a because the current scope is always smaller, for example:

fn foo<'a>(info: AccountInfo<'a>) {
    Account::try_from(&info); // not possible because reference cannot live as long as 'a
}

Yeah, this should be fixed with #3340. See the "Details" section of #2770 for more information about the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lang
Projects
None yet
Development

No branches or pull requests

2 participants