From 05ddbf3b91285d1303a1c2a5a3585ef3adf432d8 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Wed, 4 Oct 2023 23:09:43 +0900 Subject: [PATCH] Define generic AbiExample for OnceLock (#33520) * Define generic AbiExample for OnceLock * Guard with cfg... cargo-test-sbf (governance/addin-mock/program, governance/program): error[E0658]: use of unstable library feature 'once_cell' --> src/abi_example.rs:559:36 | 559 | impl AbiExample for std::sync::OnceLock { | ^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #74465 for more information = help: add `#![feature(once_cell)]` to the crate attributes to enable --- frozen-abi/src/abi_example.rs | 7 +++++++ vote/src/vote_account.rs | 26 ++------------------------ 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/frozen-abi/src/abi_example.rs b/frozen-abi/src/abi_example.rs index c7765c4a5..976668d48 100644 --- a/frozen-abi/src/abi_example.rs +++ b/frozen-abi/src/abi_example.rs @@ -555,3 +555,10 @@ impl AbiEnumVisitor for Result { digester.create_child() } } + +#[cfg(not(target_os = "solana"))] +impl AbiExample for std::sync::OnceLock { + fn example() -> Self { + Self::from(T::example()) + } +} diff --git a/vote/src/vote_account.rs b/vote/src/vote_account.rs index cd4d538b2..c4ddd43b2 100644 --- a/vote/src/vote_account.rs +++ b/vote/src/vote_account.rs @@ -1,5 +1,3 @@ -#[cfg(RUSTC_WITH_SPECIALIZATION)] -use solana_frozen_abi::abi_example::AbiExample; use { itertools::Itertools, serde::ser::{Serialize, Serializer}, @@ -30,7 +28,7 @@ pub enum Error { InvalidOwner(/*owner:*/ Pubkey), } -#[derive(Debug)] +#[derive(Debug, AbiExample)] struct VoteAccountInner { account: AccountSharedData, vote_state: OnceLock>, @@ -38,7 +36,7 @@ struct VoteAccountInner { pub type VoteAccountsHashMap = HashMap; -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Deserialize, AbiExample)] #[serde(from = "Arc")] pub struct VoteAccounts { vote_accounts: Arc, @@ -321,26 +319,6 @@ impl Serialize for VoteAccounts { } } -#[cfg(RUSTC_WITH_SPECIALIZATION)] -impl AbiExample for VoteAccountInner { - fn example() -> Self { - Self { - account: AccountSharedData::example(), - vote_state: OnceLock::from(Result::::example()), - } - } -} - -#[cfg(RUSTC_WITH_SPECIALIZATION)] -impl AbiExample for VoteAccounts { - fn example() -> Self { - Self { - vote_accounts: Arc::::example(), - staked_nodes: OnceLock::from(Arc::>::example()), - } - } -} - #[cfg(test)] mod tests { use {